Changeset 391 for python/trunk/Doc/library/multiprocessing.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/multiprocessing.rst
r2 r391 29 29 .. note:: 30 30 31 Functionality within this package requires that the ``__main__`` m ethodbe31 Functionality within this package requires that the ``__main__`` module be 32 32 importable by the children. This is covered in :ref:`multiprocessing-programming` 33 33 however it is worth pointing out here. This means that some examples, such … … 82 82 print title 83 83 print 'module name:', __name__ 84 print 'parent process:', os.getppid() 84 if hasattr(os, 'getppid'): # only available on Unix 85 print 'parent process:', os.getppid() 85 86 print 'process id:', os.getpid() 86 87 … … 108 109 **Queues** 109 110 110 The :class:` Queue` class is a near clone of :class:`Queue.Queue`. For111 The :class:`~multiprocessing.Queue` class is a near clone of :class:`Queue.Queue`. For 111 112 example:: 112 113 … … 217 218 typecodes of the kind used by the :mod:`array` module: ``'d'`` indicates a 218 219 double precision float and ``'i'`` indicates a signed integer. These shared 219 objects will be process and thread 220 objects will be process and thread-safe. 220 221 221 222 For more flexibility in using shared memory one can use the … … 232 233 :class:`dict`, :class:`Namespace`, :class:`Lock`, :class:`RLock`, 233 234 :class:`Semaphore`, :class:`BoundedSemaphore`, :class:`Condition`, 234 :class:`Event`, :class:` Queue`, :class:`Value` and :class:`Array`. For235 :class:`Event`, :class:`~multiprocessing.Queue`, :class:`Value` and :class:`Array`. For 235 236 example, :: 236 237 … … 283 284 if __name__ == '__main__': 284 285 pool = Pool(processes=4) # start 4 worker processes 285 result = pool.apply_async(f, [10]) 286 result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously 286 287 print result.get(timeout=1) # prints "100" unless your computer is *very* slow 287 288 print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]" 288 289 290 Note that the methods of a pool should only ever be used by the 291 process which created it. 292 289 293 290 294 Reference … … 298 302 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 299 303 300 .. class:: Process( [group[, target[, name[, args[, kwargs]]]]])304 .. class:: Process(group=None, target=None, name=None, args=(), kwargs={}) 301 305 302 306 Process objects represent activity that is run in a separate process. The … … 377 381 terminated when its parent process exits. Additionally, these are **not** 378 382 Unix daemons or services, they are normal processes that will be 379 terminated (and not joined) if non-da meonic processes have exited.380 381 In addition to the :class:` Threading.Thread` API, :class:`Process` objects383 terminated (and not joined) if non-daemonic processes have exited. 384 385 In addition to the :class:`threading.Thread` API, :class:`Process` objects 382 386 also support the following attributes and methods: 383 387 … … 398 402 399 403 When :mod:`multiprocessing` is initialized the main process is assigned a 400 random string using :func:`os. random`.404 random string using :func:`os.urandom`. 401 405 402 406 When a :class:`Process` object is created, it will inherit the … … 409 413 410 414 Terminate the process. On Unix this is done using the ``SIGTERM`` signal; 411 on Windows :c func:`TerminateProcess` is used. Note that exit handlers and415 on Windows :c:func:`TerminateProcess` is used. Note that exit handlers and 412 416 finally clauses, etc., will not be executed. 413 417 … … 423 427 cause other processes to deadlock. 424 428 425 Note that the :meth:`start`, :meth:`join`, :meth:`is_alive` and426 : attr:`exit_code` methods should only be called by the process that created427 the process object.429 Note that the :meth:`start`, :meth:`join`, :meth:`is_alive`, 430 :meth:`terminate` and :attr:`exitcode` methods should only be called by 431 the process that created the process object. 428 432 429 433 Example usage of some of the methods of :class:`Process`: … … 465 469 processes) or a queue (which allows multiple producers and consumers). 466 470 467 The :class:` Queue` and :class:`JoinableQueue` types are multi-producer,471 The :class:`~multiprocessing.Queue`, :class:`multiprocessing.queues.SimpleQueue` and :class:`JoinableQueue` types are multi-producer, 468 472 multi-consumer FIFO queues modelled on the :class:`Queue.Queue` class in the 469 standard library. They differ in that :class:` Queue` lacks the473 standard library. They differ in that :class:`~multiprocessing.Queue` lacks the 470 474 :meth:`~Queue.Queue.task_done` and :meth:`~Queue.Queue.join` methods introduced 471 475 into Python 2.5's :class:`Queue.Queue` class. … … 473 477 If you use :class:`JoinableQueue` then you **must** call 474 478 :meth:`JoinableQueue.task_done` for each task removed from the queue or else the 475 semaphore used to count the number of unfinished tasks may eventually overflow 479 semaphore used to count the number of unfinished tasks may eventually overflow, 476 480 raising an exception. 477 481 … … 486 490 :mod:`Queue`. 487 491 492 .. note:: 493 494 When an object is put on a queue, the object is pickled and a 495 background thread later flushes the pickled data to an underlying 496 pipe. This has some consequences which are a little surprising, 497 but should not cause any practical difficulties -- if they really 498 bother you then you can instead use a queue created with a 499 :ref:`manager <multiprocessing-managers>`. 500 501 (1) After putting an object on an empty queue there may be an 502 infinitesimal delay before the queue's :meth:`~Queue.empty` 503 method returns :const:`False` and :meth:`~Queue.get_nowait` can 504 return without raising :exc:`Queue.Empty`. 505 506 (2) If multiple processes are enqueuing objects, it is possible for 507 the objects to be received at the other end out-of-order. 508 However, objects enqueued by the same process will always be in 509 the expected order with respect to each other. 488 510 489 511 .. warning:: 490 512 491 513 If a process is killed using :meth:`Process.terminate` or :func:`os.kill` 492 while it is trying to use a :class:` Queue`, then the data in the queue is493 likely to become corrupted. This may cause any other process esto get an514 while it is trying to use a :class:`~multiprocessing.Queue`, then the data in the queue is 515 likely to become corrupted. This may cause any other process to get an 494 516 exception when it tries to use the queue later on. 495 517 … … 497 519 498 520 As mentioned above, if a child process has put items on a queue (and it has 499 not used :meth:`JoinableQueue.cancel_join_thread`), then that process will 521 not used :meth:`JoinableQueue.cancel_join_thread 522 <multiprocessing.Queue.cancel_join_thread>`), then that process will 500 523 not terminate until all buffered items have been flushed to the pipe. 501 524 … … 532 555 standard library's :mod:`Queue` module are raised to signal timeouts. 533 556 534 :class:` Queue` implements all the methods of :class:`Queue.Queue` except for557 :class:`~multiprocessing.Queue` implements all the methods of :class:`Queue.Queue` except for 535 558 :meth:`~Queue.Queue.task_done` and :meth:`~Queue.Queue.join`. 536 559 … … 553 576 multithreading/multiprocessing semantics, this is not reliable. 554 577 555 .. method:: put( item[, block[, timeout]])556 557 Put iteminto the queue. If the optional argument *block* is ``True``578 .. method:: put(obj[, block[, timeout]]) 579 580 Put obj into the queue. If the optional argument *block* is ``True`` 558 581 (the default) and *timeout* is ``None`` (the default), block if necessary until 559 582 a free slot is available. If *timeout* is a positive number, it blocks at … … 564 587 ignored in that case). 565 588 566 .. method:: put_nowait( item)567 568 Equivalent to ``put( item, False)``.589 .. method:: put_nowait(obj) 590 591 Equivalent to ``put(obj, False)``. 569 592 570 593 .. method:: get([block[, timeout]]) … … 579 602 580 603 .. method:: get_nowait() 581 get_no_wait()582 604 583 605 Equivalent to ``get(False)``. 584 606 585 :class:` multiprocessing.Queue` has a few additional methods not found in607 :class:`~multiprocessing.Queue` has a few additional methods not found in 586 608 :class:`Queue.Queue`. These methods are usually unnecessary for most 587 609 code: … … 610 632 exits -- see :meth:`join_thread`. 611 633 634 A better name for this method might be 635 ``allow_exit_without_flush()``. It is likely to cause enqueued 636 data to lost, and you almost certainly will not need to use it. 637 It is really only there if you need the current process to exit 638 immediately without waiting to flush enqueued data to the 639 underlying pipe, and you don't care about lost data. 640 641 642 .. class:: multiprocessing.queues.SimpleQueue() 643 644 It is a simplified :class:`~multiprocessing.Queue` type, very close to a locked :class:`Pipe`. 645 646 .. method:: empty() 647 648 Return ``True`` if the queue is empty, ``False`` otherwise. 649 650 .. method:: get() 651 652 Remove and return an item from the queue. 653 654 .. method:: put(item) 655 656 Put *item* into the queue. 657 612 658 613 659 .. class:: JoinableQueue([maxsize]) 614 660 615 :class:`JoinableQueue`, a :class:` Queue` subclass, is a queue which661 :class:`JoinableQueue`, a :class:`~multiprocessing.Queue` subclass, is a queue which 616 662 additionally has :meth:`task_done` and :meth:`join` methods. 617 663 … … 623 669 is complete. 624 670 625 If a :meth:`~Queue. join` is currently blocking, it will resume when all671 If a :meth:`~Queue.Queue.join` is currently blocking, it will resume when all 626 672 items have been processed (meaning that a :meth:`task_done` call was 627 673 received for every item that had been :meth:`~Queue.put` into the queue). … … 639 685 :meth:`task_done` to indicate that the item was retrieved and all work on 640 686 it is complete. When the count of unfinished tasks drops to zero, 641 :meth:`~Queue. join` unblocks.687 :meth:`~Queue.Queue.join` unblocks. 642 688 643 689 … … 693 739 do some thing like :: 694 740 695 set Executable(os.path.join(sys.exec_prefix, 'pythonw.exe'))741 set_executable(os.path.join(sys.exec_prefix, 'pythonw.exe')) 696 742 697 743 before they can create child processes. (Windows only) … … 712 758 strings. They can be thought of as message oriented connected sockets. 713 759 714 Connection objects usually created using :func:`Pipe` -- see also760 Connection objects are usually created using :func:`Pipe` -- see also 715 761 :ref:`multiprocessing-listeners-clients`. 716 762 … … 722 768 using :meth:`recv`. 723 769 724 The object must be picklable. 770 The object must be picklable. Very large pickles (approximately 32 MB+, 771 though it depends on the OS) may raise a :exc:`ValueError` exception. 725 772 726 773 .. method:: recv() 727 774 728 775 Return an object sent from the other end of the connection using 729 :meth:`send`. Raises :exc:`EOFError` if there is nothing left to receive 776 :meth:`send`. Blocks until there its something to receive. Raises 777 :exc:`EOFError` if there is nothing left to receive 730 778 and the other end was closed. 731 779 732 780 .. method:: fileno() 733 781 734 Return sthe file descriptor or handle used by the connection.782 Return the file descriptor or handle used by the connection. 735 783 736 784 .. method:: close() … … 754 802 755 803 If *offset* is given then data is read from that position in *buffer*. If 756 *size* is given then that many bytes will be read from buffer. 804 *size* is given then that many bytes will be read from buffer. Very large 805 buffers (approximately 32 MB+, though it depends on the OS) may raise a 806 :exc:`ValueError` exception 757 807 758 808 .. method:: recv_bytes([maxlength]) 759 809 760 810 Return a complete message of byte data sent from the other end of the 761 connection as a string. Raises :exc:`EOFError` if there is nothing left 811 connection as a string. Blocks until there is something to receive. 812 Raises :exc:`EOFError` if there is nothing left 762 813 to receive and the other end has closed. 763 814 … … 769 820 770 821 Read into *buffer* a complete message of byte data sent from the other end 771 of the connection and return the number of bytes in the message. Raises 822 of the connection and return the number of bytes in the message. Blocks 823 until there is something to receive. Raises 772 824 :exc:`EOFError` if there is nothing left to receive and the other end was 773 825 closed. … … 837 889 A bounded semaphore object: a clone of :class:`threading.BoundedSemaphore`. 838 890 839 (On Mac OS X this is indistinguishable from :class:`Semaphore` because891 (On Mac OS X, this is indistinguishable from :class:`Semaphore` because 840 892 ``sem_getvalue()`` is not implemented on that platform). 841 893 … … 850 902 851 903 A clone of :class:`threading.Event`. 904 This method returns the state of the internal semaphore on exit, so it 905 will always return ``True`` except if a timeout is given and the operation 906 times out. 907 908 .. versionchanged:: 2.7 909 Previously, the method always returned ``None``. 852 910 853 911 .. class:: Lock() … … 861 919 .. class:: Semaphore([value]) 862 920 863 A boundedsemaphore object: a clone of :class:`threading.Semaphore`.921 A semaphore object: a clone of :class:`threading.Semaphore`. 864 922 865 923 .. note:: … … 873 931 ignored. 874 932 875 .. note:: 876 On OS/X ``sem_timedwait`` is unsupported, so timeout arguments for the 877 aforementioned :meth:`acquire` methods will be ignored on OS/X. 933 On Mac OS X, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with 934 a timeout will emulate that function's behavior using a sleeping loop. 878 935 879 936 .. note:: … … 994 1051 995 1052 If *lock* is ``True`` (the default) then a new lock object is created to 996 synchronize access to the value. If *lock* is a :class:`Lock` or 997 :class:`RLock` object then that will be used to synchronize access to the 1053 synchronize access to the value. If *lock* is a 1054 :class:`~multiprocessing.Lock` or :class:`~multiprocessing.RLock` object 1055 then that will be used to synchronize access to the 998 1056 value. If *lock* is ``False`` then access to the returned object will not be 999 1057 automatically protected by a lock, so it will not necessarily be … … 1009 1067 1010 1068 If *lock* is ``True`` (the default) then a new lock object is created to 1011 synchronize access to the value. If *lock* is a :class:` Lock` or1012 :class:` RLock` object then that will be used to synchronize access to the1069 synchronize access to the value. If *lock* is a :class:`~multiprocessing.Lock` or 1070 :class:`~multiprocessing.RLock` object then that will be used to synchronize access to the 1013 1071 value. If *lock* is ``False`` then access to the returned object will not be 1014 1072 automatically protected by a lock, so it will not necessarily be … … 1125 1183 Create a BaseManager object. 1126 1184 1127 Once created one should call :meth:`start` or :meth:`serve_forever` to ensure1185 Once created one should call :meth:`start` or ``get_server().serve_forever()`` to ensure 1128 1186 that the manager object refers to a started manager process. 1129 1187 … … 1136 1194 must be a string. 1137 1195 1138 .. method:: start() 1139 1140 Start a subprocess to start the manager. 1141 1142 .. method:: serve_forever() 1143 1144 Run the server in the current process. 1196 .. method:: start([initializer[, initargs]]) 1197 1198 Start a subprocess to start the manager. If *initializer* is not ``None`` 1199 then the subprocess will call ``initializer(*initargs)`` when it starts. 1145 1200 1146 1201 .. method:: get_server() … … 1195 1250 where no exposed list is specified, all "public methods" of the shared 1196 1251 object will be accessible. (Here a "public method" means any attribute 1197 which has a :meth:` __call__` method and whose name does not begin with1198 ``'_'``.)1252 which has a :meth:`~object.__call__` method and whose name does not begin 1253 with ``'_'``.) 1199 1254 1200 1255 *method_to_typeid* is a mapping used to specify the return type of those … … 1281 1336 1282 1337 Create a shared ``list`` object and return a proxy for it. 1338 1339 .. note:: 1340 1341 Modifications to mutable values or items in dict and list proxies will not 1342 be propagated through the manager, because the proxy has no way of knowing 1343 when its values or items are modified. To modify such an item, you can 1344 re-assign the modified object to the container proxy:: 1345 1346 # create a list proxy and append a mutable object (a dictionary) 1347 lproxy = manager.list() 1348 lproxy.append({}) 1349 # now mutate the dictionary 1350 d = lproxy[0] 1351 d['a'] = 1 1352 d['b'] = 2 1353 # at this point, the changes to d are not yet synced, but by 1354 # reassigning the dictionary, the proxy is notified of the change 1355 lproxy[0] = d 1283 1356 1284 1357 … … 1307 1380 1308 1381 To create one's own manager, one creates a subclass of :class:`BaseManager` and 1309 use the :meth:`~BaseManager.register` classmethod to register new types or1382 uses the :meth:`~BaseManager.register` classmethod to register new types or 1310 1383 callables with the manager class. For example:: 1311 1384 … … 1472 1545 argument of :meth:`BaseManager.register`. 1473 1546 1474 If an exception is raised by the call, then thenis re-raised by1547 If an exception is raised by the call, then is re-raised by 1475 1548 :meth:`_callmethod`. If some other exception is raised in the manager's 1476 1549 process then this is converted into a :exc:`RemoteError` exception and is … … 1528 1601 with the :class:`Pool` class. 1529 1602 1530 .. class:: multiprocessing.Pool([processes[, initializer[, initargs ]]])1603 .. class:: multiprocessing.Pool([processes[, initializer[, initargs[, maxtasksperchild]]]]) 1531 1604 1532 1605 A process pool object which controls a pool of worker processes to which jobs … … 1539 1612 ``initializer(*initargs)`` when it starts. 1540 1613 1614 Note that the methods of the pool object should only be called by 1615 the process which created the pool. 1616 1617 .. versionadded:: 2.7 1618 *maxtasksperchild* is the number of tasks a worker process can complete 1619 before it will exit and be replaced with a fresh worker process, to enable 1620 unused resources to be freed. The default *maxtasksperchild* is None, which 1621 means worker processes will live as long as the pool. 1622 1623 .. note:: 1624 1625 Worker processes within a :class:`Pool` typically live for the complete 1626 duration of the Pool's work queue. A frequent pattern found in other 1627 systems (such as Apache, mod_wsgi, etc) to free resources held by 1628 workers is to allow a worker within a pool to complete only a set 1629 amount of work before being exiting, being cleaned up and a new 1630 process spawned to replace the old one. The *maxtasksperchild* 1631 argument to the :class:`Pool` exposes this ability to the end user. 1632 1541 1633 .. method:: apply(func[, args[, kwds]]) 1542 1634 1543 Equivalent of the :func:`apply` built-in function. It blocks till the1544 result is ready . Given this blocks, :meth:`apply_async` is better suited1545 for performing work in parallel. Additionally, the passed1546 in function is only executed in one of theworkers of the pool.1635 Equivalent of the :func:`apply` built-in function. It blocks until the 1636 result is ready, so :meth:`apply_async` is better suited for performing 1637 work in parallel. Additionally, *func* is only executed in one of the 1638 workers of the pool. 1547 1639 1548 1640 .. method:: apply_async(func[, args[, kwds[, callback]]]) … … 1558 1650 1559 1651 A parallel equivalent of the :func:`map` built-in function (it supports only 1560 one *iterable* argument though). It blocks till the result is ready.1652 one *iterable* argument though). It blocks until the result is ready. 1561 1653 1562 1654 This method chops the iterable into a number of chunks which it submits to … … 1579 1671 The *chunksize* argument is the same as the one used by the :meth:`.map` 1580 1672 method. For very long iterables using a large value for *chunksize* can 1581 make makethe job complete **much** faster than using the default value of1673 make the job complete **much** faster than using the default value of 1582 1674 ``1``. 1583 1675 … … 1669 1761 1670 1762 Usually message passing between processes is done using queues or by using 1671 :class:`Connection` objects returned by :func:`Pipe`. 1763 :class:`~multiprocessing.Connection` objects returned by 1764 :func:`~multiprocessing.Pipe`. 1672 1765 1673 1766 However, the :mod:`multiprocessing.connection` module allows some extra … … 1686 1779 :exc:`AuthenticationError` is raised. 1687 1780 1688 .. function:: answer Challenge(connection, authkey)1781 .. function:: answer_challenge(connection, authkey) 1689 1782 1690 1783 Receive a message, calculate the digest of the message using *authkey* as the … … 1735 1828 1736 1829 If the listener object uses a socket then *backlog* (1 by default) is passed 1737 to the :meth:`listen` method of the socket once it has been bound. 1830 to the :meth:`~socket.socket.listen` method of the socket once it has been 1831 bound. 1738 1832 1739 1833 If *authenticate* is ``True`` (``False`` by default) or *authkey* is not … … 1752 1846 1753 1847 Accept a connection on the bound socket or named pipe of the listener 1754 object and return a :class:`Connection` object. If authentication is 1755 attempted and fails, then :exc:`AuthenticationError` is raised. 1848 object and return a :class:`~multiprocessing.Connection` object. If 1849 authentication is attempted and fails, then 1850 :exc:`~multiprocessing.AuthenticationError` is raised. 1756 1851 1757 1852 .. method:: close() … … 1849 1944 ~~~~~~~~~~~~~~~~~~~ 1850 1945 1851 When one uses :meth:`Connection.recv`, the data received is automatically 1946 When one uses :meth:`Connection.recv <multiprocessing.Connection.recv>`, the 1947 data received is automatically 1852 1948 unpickled. Unfortunately unpickling data from an untrusted source is a security 1853 1949 risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module … … 1998 2094 On Unix when a process finishes but has not been joined it becomes a zombie. 1999 2095 There should never be very many because each time a new process starts (or 2000 :func:`active_children` is called) all completed processes which have not 2001 yet been joined will be joined. Also calling a finished process's 2002 :meth:`Process.is_alive` will join the process. Even so it is probably good 2096 :func:`~multiprocessing.active_children` is called) all completed processes 2097 which have not yet been joined will be joined. Also calling a finished 2098 process's :meth:`Process.is_alive <multiprocessing.Process.is_alive>` will 2099 join the process. Even so it is probably good 2003 2100 practice to explicitly join all the processes that you start. 2004 2101 … … 2008 2105 that child processes can use them. However, one should generally avoid 2009 2106 sending shared objects to other processes using pipes or queues. Instead 2010 you should arrange the program so that a process which need access to a2107 you should arrange the program so that a process which needs access to a 2011 2108 shared resource created elsewhere can inherit it from an ancestor process. 2012 2109 2013 2110 Avoid terminating processes 2014 2111 2015 Using the :meth:`Process.terminate` method to stop a process is liable to 2112 Using the :meth:`Process.terminate <multiprocessing.Process.terminate>` 2113 method to stop a process is liable to 2016 2114 cause any shared resources (such as locks, semaphores, pipes and queues) 2017 2115 currently being used by the process to become broken or unavailable to other … … 2019 2117 2020 2118 Therefore it is probably best to only consider using 2021 :meth:`Process.terminate` on processes which never use any shared resources. 2119 :meth:`Process.terminate <multiprocessing.Process.terminate>` on processes 2120 which never use any shared resources. 2022 2121 2023 2122 Joining processes that use queues … … 2026 2125 terminating until all the buffered items are fed by the "feeder" thread to 2027 2126 the underlying pipe. (The child process can call the 2028 :meth:` Queue.cancel_join_thread` method of the queue to avoid this behaviour.)2127 :meth:`~multiprocessing.Queue.cancel_join_thread` method of the queue to avoid this behaviour.) 2029 2128 2030 2129 This means that whenever you use a queue you need to make sure that all … … 2087 2186 Process(target=f, args=(lock,)).start() 2088 2187 2089 Beware replacing sys.stdinwith a "file like object"2188 Beware of replacing :data:`sys.stdin` with a "file like object" 2090 2189 2091 2190 :mod:`multiprocessing` originally unconditionally called:: … … 2103 2202 to applications which replace :func:`sys.stdin` with a "file-like object" 2104 2203 with output buffering. This danger is that if multiple processes call 2105 : func:`close()` on this file-like object, it could result in the same2204 :meth:`~io.IOBase.close()` on this file-like object, it could result in the same 2106 2205 data being flushed to the object multiple times, resulting in corruption. 2107 2206 … … 2132 2231 that instead. 2133 2232 2134 Also, if you subclass :class:`Process` then make sure that instances will be 2135 picklable when the :meth:`Process.start` method is called. 2233 Also, if you subclass :class:`~multiprocessing.Process` then make sure that 2234 instances will be picklable when the :meth:`Process.start 2235 <multiprocessing.Process.start>` method is called. 2136 2236 2137 2237 Global variables … … 2139 2239 Bear in mind that if code run in a child process tries to access a global 2140 2240 variable, then the value it sees (if any) may not be the same as the value 2141 in the parent process at the time that :meth:`Process.start` was called. 2241 in the parent process at the time that :meth:`Process.start 2242 <multiprocessing.Process.start>` was called. 2142 2243 2143 2244 However, global variables which are just module level constants cause no … … 2194 2295 2195 2296 2196 Using :class:` Pool`:2297 Using :class:`~multiprocessing.pool.Pool`: 2197 2298 2198 2299 .. literalinclude:: ../includes/mp_pool.py … … 2204 2305 2205 2306 2206 An showing how to use queues to feed tasks to a collection of worker process and2207 collect the results:2307 An example showing how to use queues to feed tasks to a collection of worker 2308 processes and collect the results: 2208 2309 2209 2310 .. literalinclude:: ../includes/mp_workers.py
Note:
See TracChangeset
for help on using the changeset viewer.