Starts a fully independent subprocess with no parent. :param executable: executable :param args: arguments to the executable, eg: ["--param1_key=param1_val", "-vvv"] :return: pid of the grandchild process
(executable, *args)
| 13 | |
| 14 | |
| 15 | def start_detached(executable, *args): |
| 16 | """Starts a fully independent subprocess with no parent. |
| 17 | :param executable: executable |
| 18 | :param args: arguments to the executable, |
| 19 | eg: ["--param1_key=param1_val", "-vvv"] |
| 20 | :return: pid of the grandchild process """ |
| 21 | import multiprocessing |
| 22 | |
| 23 | reader, writer = multiprocessing.Pipe(False) # Create pipe |
| 24 | multiprocessing.Process( |
| 25 | target=_start_detached, |
| 26 | args=(executable, *args), |
| 27 | kwargs={"writer": writer}, |
| 28 | daemon=True, |
| 29 | ).start() |
| 30 | # Receive pid from pipe |
| 31 | pid = reader.recv() |
| 32 | REGISTERED.append(pid) |
| 33 | # Close pipes |
| 34 | writer.close() |
| 35 | reader.close() |
| 36 | return pid |
| 37 | |
| 38 | |
| 39 | def _start_detached(executable, *args, writer=None): |