1

I'm running apache with django and mod_wsgi enabled in 2 different processes.

I read that the second process is a on-change listener for reloading code on change, but for some reason the ready() function of my AppConfig class is being executed twice. This function should only run once.

I understood that running django runserver with the --noreload flag will resolve the problem on development mode, but I cannot find a solution for this in production mode on my apache webserver.

I have two questions:

  1. How can I run with only one process in production or at least make only one process run the ready() function ?

  2. Is there a way to make the ready() function run not in a lazy mode? By this, I mean execute only on on server startup, not on first request.

For further explanation, I am experiencing a scenario as follows: The ready() function creates a folder listener such as pyinotify. That listener will listen on a folder on my server and enqueue a task on any changes. I am seeing this listener executed twice on any changes to a single file in the monitored directory. This leads me to believe that both processes are running my listener.

4

2 回答 2

2

不,第二个进程不是 onchange 监听器——我不知道你在哪里读到的。开发服务器会发生这种情况,而不是 mod_wsgi。

您不应试图阻止 Apache 为多个进程提供服务。如果这样做,您的站点的速度将大大降低:它一次只能处理一个请求,其他请求将排队等待第一个请求完成。除了玩具网站之外,这对任何东西都没有好处。

相反,您应该修复您的 AppConfig。与其盲目地产生一个监听器,你应该在开始一个新的监听器之前检查它是否已经被创建。

于 2015-02-04T12:18:21.240 回答
0

您不应该阻止产生多个进程,因为这是一件好事,尤其是在生产环境中。您应该考虑使用一些与 django 分开的外部工具,或者添加检查文件夹监听是否已经在运行(例如监控 PID 文件的持久性及其内容)。

于 2015-02-04T12:00:48.447 回答