MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/test/_test_multiprocessing.py:2187–2213  ·  view source on GitHub ↗

Construct a bunch of `n` threads running the same function `f`. If `wait_before_exit` is True, the threads won't terminate until do_finish() is called.

(self, namespace, f, args, n, wait_before_exit=False)

Source from the content-addressed store, hash-verified

2185 A bunch of threads.
2186 """
2187 def __init__(self, namespace, f, args, n, wait_before_exit=False):
2188 """
2189 Construct a bunch of `n` threads running the same function `f`.
2190 If `wait_before_exit` is True, the threads won't terminate until
2191 do_finish() is called.
2192 """
2193 self.f = f
2194 self.args = args
2195 self.n = n
2196 self.started = namespace.DummyList()
2197 self.finished = namespace.DummyList()
2198 self._can_exit = namespace.Event()
2199 if not wait_before_exit:
2200 self._can_exit.set()
2201
2202 threads = []
2203 for i in range(n):
2204 p = namespace.Process(target=self.task)
2205 p.daemon = True
2206 p.start()
2207 threads.append(p)
2208
2209 def finalize(threads):
2210 for p in threads:
2211 p.join()
2212
2213 self._finalizer = weakref.finalize(self, finalize, threads)
2214
2215 def task(self):
2216 pid = os.getpid()

Callers 1

__init__Method · 0.45

Calls 7

DummyListMethod · 0.80
EventMethod · 0.80
setMethod · 0.45
ProcessMethod · 0.45
startMethod · 0.45
appendMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected