简体   繁体   English

在Django中分叉后关闭TCP端口80和443

[英]Close TCP port 80 and 443 after forking in Django

I am trying to fork() and exec() a new python script process from within a Django app that is running in apache2/WSGI Python. 我正在尝试从一个在apache2 / WSGI Python中运行的Django应用程序中fork()和exec()一个新的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. 新的python进程被守护进程,因此它不与apache2保持任何关联,但我知道HTTP端口仍处于打开状态。 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. 新进程杀死apache2,但结果是新的python进程现在保持端口80和443打开,我不想要这个。

How do I close port 80 and 443 from within the new python process? 如何在新的python进程中关闭端口80和443? 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: 如果您使用的subprocess模块来执行脚本,该close_fds参数传递给Popen构造可能会做你想要什么:

If close_fds is true, all file descriptors except 0, 1 and 2 will be closed before the child process is executed. 如果close_fds为true,则在执行子进程之前将关闭除0,1和2之外的所有文件描述符。

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. 假设它们不是简单地关闭,前三个文件描述符传统上是stdinstdoutstderr ,因此Django应用程序中的侦听套接字将在子进程中关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM