I am trying to fork() and exec() a new python script process from within a Django app that is running in apache2/WSGI Python. The new python process is daemonized so that it doesn't hold any association to apache2, but I know the HTTP ports are still open. The new process kills apache2, but as a result the new python process now holds port 80 and 443 open, and I don't want this.
How do I close port 80 and 443 from within the new python process? Is there a way to gain access to the socket handle descriptors so they can be closed?
If you use the subprocess
module to execute the script, the close_fds
argument to the Popen
constructor will probably do what you want:
If close_fds is true, all file descriptors except 0, 1 and 2 will be closed before the child process is executed.
Assuming they weren't simply closed, the first three file descriptors are traditionally stdin
, stdout
and stderr
, so the listening sockets in the Django application will be among those closed in the child process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With