| 180 | # Currently we only add this API first, we can consider adding it to documentation as |
| 181 | # needed in the future. |
| 182 | def start_processes( |
| 183 | fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn" |
| 184 | ): |
| 185 | mp = multiprocessing.get_context(start_method) |
| 186 | error_queues = [] |
| 187 | processes = [] |
| 188 | for i in range(nprocs): |
| 189 | error_queue = mp.SimpleQueue() |
| 190 | process = mp.Process( |
| 191 | target=_wrap, args=(fn, i, args, error_queue), daemon=daemon, |
| 192 | ) |
| 193 | process.start() |
| 194 | error_queues.append(error_queue) |
| 195 | processes.append(process) |
| 196 | |
| 197 | context = ProcessContext(processes, error_queues) |
| 198 | if not join: |
| 199 | return context |
| 200 | |
| 201 | # Loop on join until it returns True or raises an exception. |
| 202 | while not context.join(): |
| 203 | pass |
| 204 | |
| 205 | |
| 206 | def spawn(fn, args=(), nprocs=1, join=True, daemon=False, start_method="spawn"): |