annotate Lib/multiprocessing/__init__.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 05f90cecb2a2
children debe61673a8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
1 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
2 # Package analogous to 'threading.py' but using processes
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
3 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
4 # multiprocessing/__init__.py
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
5 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
6 # This package is intended to duplicate the functionality (and much of
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
7 # the API) of threading.py but uses processes instead of threads. A
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
8 # subpackage 'multiprocessing.dummy' has the same API but is a simple
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
9 # wrapper for 'threading'.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
10 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
11 # Try calling `multiprocessing.doc.main()` to read the html
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
12 # documentation in in a webbrowser.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
13 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
14 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
15 # Copyright (c) 2006-2008, R Oudkerk
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
16 # All rights reserved.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
17 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
18 # Redistribution and use in source and binary forms, with or without
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
19 # modification, are permitted provided that the following conditions
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
20 # are met:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
21 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
22 # 1. Redistributions of source code must retain the above copyright
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
23 # notice, this list of conditions and the following disclaimer.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
24 # 2. Redistributions in binary form must reproduce the above copyright
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
25 # notice, this list of conditions and the following disclaimer in the
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
26 # documentation and/or other materials provided with the distribution.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
27 # 3. Neither the name of author nor the names of any contributors may be
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
28 # used to endorse or promote products derived from this software
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
29 # without specific prior written permission.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
30 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
31 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
32 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
33 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
34 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
35 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
36 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
37 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
38 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
39 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
40 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
41 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
42
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
43 __version__ = '0.70a1'
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
44
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
45 __all__ = [
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
46 'Process', 'current_process', 'active_children', 'freeze_support',
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
47 'Manager', 'Pipe', 'cpu_count', 'log_to_stderr', 'get_logger',
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
48 'allow_connection_pickling', 'BufferTooShort', 'TimeoutError',
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
49 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition',
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
50 'Event', 'Queue', 'JoinableQueue', 'Pool', 'Value', 'Array',
52526
05f90cecb2a2 Merged revisions 68915 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 50004
diff changeset
51 'RawValue', 'RawArray', 'SUBDEBUG', 'SUBWARNING',
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
52 ]
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
53
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
54 __author__ = 'R. Oudkerk (r.m.oudkerk@gmail.com)'
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
55
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
56 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
57 # Imports
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
58 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
59
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
60 import os
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
61 import sys
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
62
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
63 from multiprocessing.process import Process, current_process, active_children
52526
05f90cecb2a2 Merged revisions 68915 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents: 50004
diff changeset
64 from multiprocessing.util import SUBDEBUG, SUBWARNING
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
65
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
66 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
67 # Exceptions
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
68 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
69
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
70 class ProcessError(Exception):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
71 pass
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
72
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
73 class BufferTooShort(ProcessError):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
74 pass
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
75
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
76 class TimeoutError(ProcessError):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
77 pass
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
78
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
79 class AuthenticationError(ProcessError):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
80 pass
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
81
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
82 # This is down here because _multiprocessing uses BufferTooShort
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
83 import _multiprocessing
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
84
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
85 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
86 # Definitions not depending on native semaphores
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
87 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
88
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
89 def Manager():
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
90 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
91 Returns a manager associated with a running server process
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
92
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
93 The managers methods such as `Lock()`, `Condition()` and `Queue()`
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
94 can be used to create shared objects.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
95 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
96 from multiprocessing.managers import SyncManager
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
97 m = SyncManager()
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
98 m.start()
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
99 return m
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
100
48931
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
101 def Pipe(duplex=True):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
102 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
103 Returns two connection object connected by a pipe
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
104 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
105 from multiprocessing.connection import Pipe
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
106 return Pipe(duplex)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
107
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
108 def cpu_count():
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
109 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
110 Returns the number of CPUs in the system
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
111 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
112 if sys.platform == 'win32':
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
113 try:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
114 num = int(os.environ['NUMBER_OF_PROCESSORS'])
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
115 except (ValueError, KeyError):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
116 num = 0
50004
3c7eef187bea Merged revisions 67398,67423-67424,67432,67440-67441,67444-67445,67454,67457,67463 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48931
diff changeset
117 elif 'bsd' in sys.platform or sys.platform == 'darwin':
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
118 try:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
119 num = int(os.popen('sysctl -n hw.ncpu').read())
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
120 except ValueError:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
121 num = 0
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
122 else:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
123 try:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
124 num = os.sysconf('SC_NPROCESSORS_ONLN')
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
125 except (ValueError, OSError, AttributeError):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
126 num = 0
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
127
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
128 if num >= 1:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
129 return num
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
130 else:
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
131 raise NotImplementedError('cannot determine number of cpus')
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
132
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
133 def freeze_support():
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
134 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
135 Check whether this is a fake forked process in a frozen executable.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
136 If so then run code specified by commandline and exit.
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
137 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
138 if sys.platform == 'win32' and getattr(sys, 'frozen', False):
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
139 from multiprocessing.forking import freeze_support
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
140 freeze_support()
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
141
48931
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
142 def get_logger():
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
143 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
144 Return package logger -- if it does not already exist then it is created
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
145 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
146 from multiprocessing.util import get_logger
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
147 return get_logger()
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
148
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
149 def log_to_stderr(level=None):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
150 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
151 Turn on logging and add a handler which prints to stderr
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
152 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
153 from multiprocessing.util import log_to_stderr
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
154 return log_to_stderr(level)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
155
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
156 def allow_connection_pickling():
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
157 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
158 Install support for sending connections and sockets between processes
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
159 '''
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
160 from multiprocessing import reduction
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
161
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
162 #
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
163 # Definitions depending on native semaphores
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
164 #
48931
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
165
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
166 def Lock():
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
167 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
168 Returns a non-recursive lock object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
169 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
170 from multiprocessing.synchronize import Lock
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
171 return Lock()
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
172
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
173 def RLock():
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
174 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
175 Returns a recursive lock object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
176 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
177 from multiprocessing.synchronize import RLock
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
178 return RLock()
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
179
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
180 def Condition(lock=None):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
181 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
182 Returns a condition object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
183 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
184 from multiprocessing.synchronize import Condition
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
185 return Condition(lock)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
186
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
187 def Semaphore(value=1):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
188 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
189 Returns a semaphore object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
190 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
191 from multiprocessing.synchronize import Semaphore
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
192 return Semaphore(value)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
193
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
194 def BoundedSemaphore(value=1):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
195 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
196 Returns a bounded semaphore object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
197 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
198 from multiprocessing.synchronize import BoundedSemaphore
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
199 return BoundedSemaphore(value)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
200
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
201 def Event():
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
202 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
203 Returns an event object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
204 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
205 from multiprocessing.synchronize import Event
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
206 return Event()
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
207
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
208 def Queue(maxsize=0):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
209 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
210 Returns a queue object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
211 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
212 from multiprocessing.queues import Queue
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
213 return Queue(maxsize)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
214
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
215 def JoinableQueue(maxsize=0):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
216 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
217 Returns a queue object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
218 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
219 from multiprocessing.queues import JoinableQueue
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
220 return JoinableQueue(maxsize)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
221
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
222 def Pool(processes=None, initializer=None, initargs=()):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
223 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
224 Returns a process pool object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
225 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
226 from multiprocessing.pool import Pool
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
227 return Pool(processes, initializer, initargs)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
228
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
229 def RawValue(typecode_or_type, *args):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
230 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
231 Returns a shared object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
232 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
233 from multiprocessing.sharedctypes import RawValue
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
234 return RawValue(typecode_or_type, *args)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
235
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
236 def RawArray(typecode_or_type, size_or_initializer):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
237 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
238 Returns a shared array
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
239 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
240 from multiprocessing.sharedctypes import RawArray
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
241 return RawArray(typecode_or_type, size_or_initializer)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
242
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
243 def Value(typecode_or_type, *args, **kwds):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
244 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
245 Returns a synchronized shared object
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
246 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
247 from multiprocessing.sharedctypes import Value
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
248 return Value(typecode_or_type, *args, **kwds)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
249
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
250 def Array(typecode_or_type, size_or_initializer, **kwds):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
251 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
252 Returns a synchronized shared array
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
253 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
254 from multiprocessing.sharedctypes import Array
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
255 return Array(typecode_or_type, size_or_initializer, **kwds)
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
256
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
257 #
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
258 #
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
259 #
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
260
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
261 if sys.platform == 'win32':
48931
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
262
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
263 def set_executable(executable):
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
264 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
265 Sets the path to a python.exe or pythonw.exe binary used to run
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
266 child processes on Windows instead of sys.executable.
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
267 Useful for people embedding Python.
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
268 '''
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
269 from multiprocessing.forking import set_executable
51f795c9530e revert r66114 for Jesse
Benjamin Peterson <benjamin@python.org>
parents: 48930
diff changeset
270 set_executable(executable)
47696
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
271
d01165fae98e darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents: 47694
diff changeset
272 __all__ += ['set_executable']