ยปCore Development>Code coverage>Lib/multiprocessing/dummy/__init__.py

Python code coverage for Lib/multiprocessing/dummy/__init__.py

#countcontent
1n/a#
2n/a# Support for the API of the multiprocessing package using threads
3n/a#
4n/a# multiprocessing/dummy/__init__.py
5n/a#
6n/a# Copyright (c) 2006-2008, R Oudkerk
7n/a# Licensed to PSF under a Contributor Agreement.
8n/a#
9n/a
10n/a__all__ = [
11n/a 'Process', 'current_process', 'active_children', 'freeze_support',
12n/a 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition',
13n/a 'Event', 'Barrier', 'Queue', 'Manager', 'Pipe', 'Pool', 'JoinableQueue'
14n/a ]
15n/a
16n/a#
17n/a# Imports
18n/a#
19n/a
20n/aimport threading
21n/aimport sys
22n/aimport weakref
23n/aimport array
24n/a
25n/afrom .connection import Pipe
26n/afrom threading import Lock, RLock, Semaphore, BoundedSemaphore
27n/afrom threading import Event, Condition, Barrier
28n/afrom queue import Queue
29n/a
30n/a#
31n/a#
32n/a#
33n/a
34n/aclass DummyProcess(threading.Thread):
35n/a
36n/a def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
37n/a threading.Thread.__init__(self, group, target, name, args, kwargs)
38n/a self._pid = None
39n/a self._children = weakref.WeakKeyDictionary()
40n/a self._start_called = False
41n/a self._parent = current_process()
42n/a
43n/a def start(self):
44n/a assert self._parent is current_process()
45n/a self._start_called = True
46n/a if hasattr(self._parent, '_children'):
47n/a self._parent._children[self] = None
48n/a threading.Thread.start(self)
49n/a
50n/a @property
51n/a def exitcode(self):
52n/a if self._start_called and not self.is_alive():
53n/a return 0
54n/a else:
55n/a return None
56n/a
57n/a#
58n/a#
59n/a#
60n/a
61n/aProcess = DummyProcess
62n/acurrent_process = threading.current_thread
63n/acurrent_process()._children = weakref.WeakKeyDictionary()
64n/a
65n/adef active_children():
66n/a children = current_process()._children
67n/a for p in list(children):
68n/a if not p.is_alive():
69n/a children.pop(p, None)
70n/a return list(children)
71n/a
72n/adef freeze_support():
73n/a pass
74n/a
75n/a#
76n/a#
77n/a#
78n/a
79n/aclass Namespace(object):
80n/a def __init__(self, **kwds):
81n/a self.__dict__.update(kwds)
82n/a def __repr__(self):
83n/a items = list(self.__dict__.items())
84n/a temp = []
85n/a for name, value in items:
86n/a if not name.startswith('_'):
87n/a temp.append('%s=%r' % (name, value))
88n/a temp.sort()
89n/a return '%s(%s)' % (self.__class__.__name__, ', '.join(temp))
90n/a
91n/adict = dict
92n/alist = list
93n/a
94n/adef Array(typecode, sequence, lock=True):
95n/a return array.array(typecode, sequence)
96n/a
97n/aclass Value(object):
98n/a def __init__(self, typecode, value, lock=True):
99n/a self._typecode = typecode
100n/a self._value = value
101n/a def _get(self):
102n/a return self._value
103n/a def _set(self, value):
104n/a self._value = value
105n/a value = property(_get, _set)
106n/a def __repr__(self):
107n/a return '<%s(%r, %r)>'%(type(self).__name__,self._typecode,self._value)
108n/a
109n/adef Manager():
110n/a return sys.modules[__name__]
111n/a
112n/adef shutdown():
113n/a pass
114n/a
115n/adef Pool(processes=None, initializer=None, initargs=()):
116n/a from ..pool import ThreadPool
117n/a return ThreadPool(processes, initializer, initargs)
118n/a
119n/aJoinableQueue = Queue