2
# Support for the API of the multiprocessing package using threads
4
# multiprocessing/dummy/__init__.py
6
# Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
10
'Process', 'current_process', 'active_children', 'freeze_support',
11
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition',
12
'Event', 'Queue', 'Manager', 'Pipe', 'Pool', 'JoinableQueue'
25
from multiprocessing import TimeoutError, cpu_count
26
from multiprocessing.dummy.connection import Pipe
27
from threading import Lock, RLock, Semaphore, BoundedSemaphore
28
from threading import Event
29
from Queue import Queue
35
class DummyProcess(threading.Thread):
37
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
38
threading.Thread.__init__(self, group, target, name, args, kwargs)
40
self._children = weakref.WeakKeyDictionary()
41
self._start_called = False
42
self._parent = current_process()
45
assert self._parent is current_process()
46
self._start_called = True
47
self._parent._children[self] = None
48
threading.Thread.start(self)
52
if self._start_called and not self.is_alive():
57
is_alive = threading.Thread.is_alive.im_func
58
get_name = threading.Thread.getName.im_func
59
set_name = threading.Thread.setName.im_func
60
is_daemon = threading.Thread.isDaemon.im_func
61
set_daemon = threading.Thread.setDaemon.im_func
67
class Condition(threading._Condition):
68
notify_all = threading._Condition.notify_all.im_func
74
Process = DummyProcess
75
current_process = threading.current_thread
76
current_process()._children = weakref.WeakKeyDictionary()
78
def active_children():
79
children = current_process()._children
80
for p in list(children):
92
class Namespace(object):
93
def __init__(self, **kwds):
94
self.__dict__.update(kwds)
96
items = self.__dict__.items()
98
for name, value in items:
99
if not name.startswith('_'):
100
temp.append('%s=%r' % (name, value))
102
return 'Namespace(%s)' % str.join(', ', temp)
107
def Array(typecode, sequence, lock=True):
108
return array.array(typecode, sequence)
111
def __init__(self, typecode, value, lock=True):
112
self._typecode = typecode
116
def _set(self, value):
118
value = property(_get, _set)
120
return '<%r(%r, %r)>'%(type(self).__name__,self._typecode,self._value)
123
return sys.modules[__name__]
128
def Pool(processes=None, initializer=None, initargs=()):
129
from multiprocessing.pool import ThreadPool
130
return ThreadPool(processes, initializer, initargs)
132
JoinableQueue = Queue