Getting Python to fork?

Christian Heimes lists at cheimes.de
Mon Feb 4 10:29:05 EST 2008


Jon Ribbens wrote:
> I think that's changing Python's idea of stdin etc but not the
> operating system's idea of them. You won't be closing the original
> file descriptors, and if you run any subprocesses they will end up
> with the original stdin/out/err. Unless sys.stdin is more magic
> than I'm aware of.

Jon is correct here. You must close or redirect the underlying C file
descriptor. Python's sys.std streams don't magically do this for you
because Python keeps a backup of the standard streams for internal
purpose in sys.__std*__. os.dup2 is the best solution.

Christian




More information about the Python-list mailing list