diff options
author | Georg Brandl <georg@python.org> | 2008-07-16 12:55:28 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-07-16 12:55:28 (GMT) |
commit | 2ee470f7f99f78348baa1e7a13007540d89d9c92 (patch) | |
tree | c8c65be74a06e665375c0d0de7ee7514e61cdb49 /Doc/whatsnew | |
parent | 38bbc4888a1fcbcedd7eb8b83ac4b070f2aeb5f2 (diff) | |
download | cpython-2ee470f7f99f78348baa1e7a13007540d89d9c92.zip cpython-2ee470f7f99f78348baa1e7a13007540d89d9c92.tar.gz cpython-2ee470f7f99f78348baa1e7a13007540d89d9c92.tar.bz2 |
Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines
#2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade.
This is a new feature, but Barry authorized adding it in the beta period.
........
r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines
Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified
by various other language standards, including C99, IEEE 754r,
and the IBM Decimal standard.
........
r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines
- Issue #2862: Make int and float freelist management consistent with other
freelists. Changes their CompactFreeList apis into ClearFreeList apis and
calls them via gc.collect().
........
r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3301: Bisect functions behaved badly when lo was negative.
........
r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments.
........
r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line
Wording changes
........
r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line
Add cautionary note on the use of PySequence_Fast_ITEMS.
........
r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines
#3317 in zipfile module, restore the previous names of global variables:
some applications relied on them.
Also remove duplicated lines.
........
r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
........
r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines
Fix for the AttributeError in test_asynchat.
........
r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines
Fixed test for asyncore.
........
r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines
- Fix bashisms in Tools/faqwiz/move-faqwiz.sh
........
r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line
fix various doc typos #3320
........
r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines
Fixed typo.
........
r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line
#1778443 robotparser fixes from Aristotelis Mikropoulos
........
r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line
Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute)
........
r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines
Add turtle into the module index.
........
r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines
Issue #3274: Use a less common identifier for the temporary variable
in Py_CLEAR().
........
r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line
Re-word
........
r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line
Add various items; move ctypes items into a subsection of their own
........
r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fixes
........
r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line
Expand the multiprocessing section
........
r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines
Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child
process rather than both parent and child.
Does anyone actually use fork1()? It appears to be a Solaris thing
but if Python is built with pthreads on Solaris, fork1() and fork()
should be the same.
........
r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line
multiprocessing/connection.py patch to remove fqdn oddness for issue 3270
........
r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line
Add missing NEWS entry for r64962
........
r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line
Revert 3270 patch: self._address is in pretty widespread use, need to revisit
........
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/2.6.rst | 200 |
1 files changed, 174 insertions, 26 deletions
diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 264ec2e..5cf29cb 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -51,7 +51,7 @@ This article explains the new features in Python 2.6. The release schedule is described in :pep:`361`; currently the final release is -scheduled for September 3 2008. +scheduled for October 1 2008. This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For @@ -526,28 +526,152 @@ environment variable. PEP 371: The ``multiprocessing`` Package ===================================================== -.. XXX I think this still needs help +The new :mod:`multiprocessing` package lets Python programs create new +processes that will perform a computation and return a result to the +parent. The parent and child processes can communicate using queues +and pipes, synchronize their operations using locks and semaphores, +and can share simple arrays of data. + +The :mod:`multiprocessing` module started out as an exact emulation of +the :mod:`threading` module using processes instead of threads. That +goal was discarded along the path to Python 2.6, but the general +approach of the module is still similar. The fundamental class +is the :class:`Process`, which is passed a callable object and +a collection of arguments. The :meth:`start` method +sets the callable running in a subprocess, after which you can call +the :meth:`is_alive` method to check whether the subprocess is still running +and the :meth:`join` method to wait for the process to exit. + +Here's a simple example where the subprocess will calculate a +factorial. The function doing the calculation is a bit strange; it's +written to take significantly longer when the input argument is a +multiple of 4. + +:: + + import time + from multiprocessing import Process, Queue + + + def factorial(queue, N): + "Compute a factorial." + # If N is a multiple of 4, this function will take much longer. + if (N % 4) == 0: + time.sleep(.05 * N/4) + + # Calculate the result + fact = 1L + for i in range(1, N+1): + fact = fact * i + + # Put the result on the queue + queue.put(fact) + + if __name__ == '__main__': + queue = Queue() + + N = 5 + + p = Process(target=factorial, args=(queue, N)) + p.start() + p.join() + + result = queue.get() + print 'Factorial', N, '=', result + +A :class:`Queue` object is created and stored as a global. The child +process will use the value of the variable when the child was created; +because it's a :class:`Queue`, parent and child can use the object to +communicate. (If the parent were to change the value of the global +variable, the child's value would be unaffected, and vice versa.) + +Two other classes, :class:`Pool` and :class:`Manager`, provide +higher-level interfaces. :class:`Pool` will create a fixed number of +worker processes, and requests can then be distributed to the workers +by calling :meth:`apply` or `apply_async`, adding a single request, +and :meth:`map` or :meth:`map_async` to distribute a number of +requests. The following code uses a :class:`Pool` to spread requests +across 5 worker processes, receiving a list of results back. + +:: + + from multiprocessing import Pool + + p = Pool(5) + result = p.map(factorial, range(1, 1000, 10)) + for v in result: + print v + +This produces the following output:: + + 1 + 39916800 + 51090942171709440000 + 8222838654177922817725562880000000 + 33452526613163807108170062053440751665152000000000 + ... + +The :class:`Manager` class creates a separate server process that can +hold master copies of Python data structures. Other processes can +then access and modify these data structures by using proxy objects. +The following example creates a shared dictionary by calling the +:meth:`dict` method; the worker processes then insert values into the +dictionary. (No locking is done automatically, which doesn't matter +in this example. :class:`Manager`'s methods also include +:meth:`Lock`, :meth:`RLock`, and :meth:`Semaphore` to create shared locks. + +:: + + import time + from multiprocessing import Pool, Manager + + def factorial(N, dictionary): + "Compute a factorial." + # Calculate the result + fact = 1L + for i in range(1, N+1): + fact = fact * i + + # Store result in dictionary + dictionary[N] = fact + + if __name__ == '__main__': + p = Pool(5) + mgr = Manager() + d = mgr.dict() # Create shared dictionary -:mod:`multiprocessing` makes it easy to distribute work over multiple processes. -Its API is similiar to that of :mod:`threading`. For example:: + # Run tasks using the pool + for N in range(1, 1000, 10): + p.apply_async(factorial, (N, d)) - from multiprocessing import Process + # Mark pool as closed -- no more tasks can be added. + p.close() - def long_hard_task(n): - print n * 43 + # Wait for tasks to exit + p.join() - for i in range(10): - Process(target=long_hard_task, args=(i)).start() + # Output results + for k, v in sorted(d.items()): + print k, v -will multiply the numbers between 0 and 10 times 43 and print out the result -concurrently. +This will produce the output:: + + 1 1 + 11 39916800 + 21 51090942171709440000 + 31 8222838654177922817725562880000000 + 41 33452526613163807108170062053440751665152000000000 + 51 1551118753287382280224243016469303211063259720016986112000000000000 .. seealso:: + The documentation for the :mod:`multiprocessing` module. + :pep:`371` - Addition of the multiprocessing package PEP written by Jesse Noller and Richard Oudkerk; implemented by Richard Oudkerk and Jesse Noller. + .. ====================================================================== .. _pep-3101: @@ -1775,21 +1899,6 @@ details. (Contributed by Raymond Hettinger.) -* XXX Describe the new ctypes calling convention that allows safe - access to errno. - (Implemented by Thomas Heller; :issue:`1798`.) - -* The :mod:`ctypes` module now supports a :class:`c_bool` datatype - that represents the C99 ``bool`` type. (Contributed by David Remahl; - :issue:`1649190`.) - - The :mod:`ctypes` string, buffer and array types also have improved - support for extended slicing syntax, - where various combinations of ``(start, stop, step)`` are supplied. - (Implemented by Thomas Wouters.) - - .. Revision 57769 - * A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes the display characters for a certain number of characters on a single line. (Contributed by Fabian Kreutz.) @@ -2628,6 +2737,45 @@ Using the module is simple:: .. ====================================================================== +ctypes Enhancements +-------------------------------------------------- + +Thomas Heller continued to maintain and enhance the +:mod:`ctypes` module. + +:mod:`ctypes` now supports a :class:`c_bool` datatype +that represents the C99 ``bool`` type. (Contributed by David Remahl; +:issue:`1649190`.) + +The :mod:`ctypes` string, buffer and array types have improved +support for extended slicing syntax, +where various combinations of ``(start, stop, step)`` are supplied. +(Implemented by Thomas Wouters.) + +.. Revision 57769 + +A new calling convention tells :mod:`ctypes` to clear the ``errno`` or +Win32 LastError variables at the outset of each wrapped call. +(Implemented by Thomas Heller; :issue:`1798`.) + +For the Unix ``errno`` variable: when creating a wrapped function, +you can supply ``use_errno=True`` as a keyword parameter +to the :func:`DLL` function +and then call the module-level methods :meth:`set_errno` +and :meth:`get_errno` to set and retrieve the error value. + +The Win32 LastError variable is supported similarly by +the :func:`DLL`, :func:`OleDLL`, and :func:`WinDLL` functions. +You supply ``use_last_error=True`` as a keyword parameter +and then call the module-level methods :meth:`set_last_error` +and :meth:`get_last_error`. + +The :func:`byref` function, used to retrieve a pointer to a ctypes +instance, now has an optional **offset** parameter that is a byte +count that will be added to the returned pointer. + +.. ====================================================================== + Improved SSL Support -------------------------------------------------- |