(
fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"
)
| 203 | # Currently we only add this API first, we can consider adding it to documentation as |
| 204 | # needed in the future. |
| 205 | def 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 | |
| 241 | def spawn(fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"): |
searching dependent graphs…