I am planning a Python script that’ll use os.fork() to create a bunch of child processes to perform some computations. The parent process will block until the children terminate.
The twist is that I need to be able to run the script both from the Unix shell using python and from ipython using %run.
In what manner should the child processes terminate to avoid breaking back into the ipython command prompt? In my experience, sys.exit() won’t do.
The following seems to work:
The trick is to use
os._exit()instead ofsys.exit(). The documentation contains the following passage: