MCPcopy Create free account
hub / github.com/pytorch/pytorch / start_processes

Function start_processes

torch/multiprocessing/spawn.py:205–238  ·  view source on GitHub ↗
(
    fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"
)

Source from the content-addressed store, hash-verified

203# Currently we only add this API first, we can consider adding it to documentation as
204# needed in the future.
205def start_processes(
206 fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"
207):
208 mp = multiprocessing.get_context(start_method)
209 error_files = []
210 processes = []
211 for i in range(nprocs):
212 # Each process is assigned a file to write tracebacks to. We
213 # use the file being non-empty to indicate an exception
214 # occurred (vs an expected shutdown). Note: this previously
215 # used a multiprocessing.Queue but that can be prone to
216 # deadlocks, so we went with a simpler solution for a one-shot
217 # message between processes.
218 tf = tempfile.NamedTemporaryFile(
219 prefix="pytorch-errorfile-", suffix=".pickle", delete=False
220 )
221 tf.close()
222 os.unlink(tf.name)
223 process = mp.Process(
224 target=_wrap,
225 args=(fn, i, args, tf.name),
226 daemon=daemon,
227 )
228 process.start()
229 error_files.append(tf.name)
230 processes.append(process)
231
232 context = ProcessContext(processes, error_files)
233 if not join:
234 return context
235
236 # Loop on join until it returns True or raises an exception.
237 while not context.join():
238 pass
239
240
241def spawn(fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"):

Callers 15

launchMethod · 0.90
test_invalid_log_dirMethod · 0.90
test_pcontext_waitMethod · 0.90
test_void_functionMethod · 0.90
test_function_raiseMethod · 0.90
test_binary_exitMethod · 0.90

Calls 7

joinMethod · 0.95
ProcessContextClass · 0.85
get_contextMethod · 0.80
rangeFunction · 0.50
closeMethod · 0.45
startMethod · 0.45
appendMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…