admin管理员组文章数量:1122832
I'm having an issue with a Flask application that I'm running using Apache and WSGI on a Raspberry Pi. The application restarts intermittently, and it seems that Apache is restarting the application creating a new process after that. I've tried several solutions, but I haven't been able to identify the exact cause of the behavior. Below are the details of my setup and the observed behavior.
Development Environment:
Hardware: Raspberry Pi Web server: Apache Flask: Running with WSGI
Observed Issue: My Flask application seems to restart (or started twice). I've added logging, and I noticed that when this happens, Apache is creating a new process to run the application. This causes problems, especially because I'm managing IPC communication between Python and another C process using FIFOs. Every time Apache creates a new process, my FIFOs get reset, and the data becomes corrupted.
Log Details Suggesting the Issue: Reviewing the logs, I see that after the following log entry: [11-21 04:13:24] p1444 '''DEBUG - Waiting for a message to be available in the outgoing queue...''' Immediately afterward, a new process seems to be created that re-executes flask_buttons.py, which is my main Flask file. I suspect this might be related to the WSGI configuration or an Apache configuration issue.
Apache Configuration File (configuration): This is my Apache config file:(see picture)
Timeout 600
<virtualHost:80>
ServerName IPAddress
WSGIDaemonProcess blackbox_flaskapp user=www-data group=www-data threads=5 processes=1 inactivity-timeout=600
WSGIScriptAlias / /var/www/BlackBox/app.wsgi
KeepAlive Off
MaxKeepAliveRequests 5000
KeepAliveTimeout 1000
<IfModule mod_headers.c>
Header always set X-Accel-Buffering "no"
Header always set Cache-Control "no-cache"
Header always set Connection "keep-alive"
</IfModule>
<Location /events>
Header set Content-Type "text/event-stream"
Header set Cache-Control "no-cache"
Header set Connection "keep-alive"
Header set Access-Control-Allow-Origin "*"
</Location>
<Directory /var/www/BlackBox/FrontMiddleEnd/SFWM_IPC_sse/static>
Require all granted
</Directory>
ErrorLog /var/www/BlackBox/logs/error.log
CustomLog /var/www/BlackBox/logs/access.log combined
</VirtualHost>
Relevant Python Code Fragment (IPC_CommHandlers.py): Here’s the code where I think the issue might be occurring. I'm using threads to handle incoming and outgoing message queues:
class IPC_Comm_Incoming_Message_Listener():
MessageQueue = None
MessageLock = None
def __init__(self):
self.MessageQueue = []
self.MessageLock = Condition()
def getMessage(self):
with self.MessageLock:
LoggerTool.instance().debug("Waiting for a message to be available in the queue...")
self.MessageLock.wait_for(lambda: len(self.MessageQueue) > 0)
LoggerTool.instance().debug(f"Message received. Queue size before pop: {len(self.MessageQueue)}")
return self.MessageQueue.pop()
def addMessage(self, message):
with self.MessageLock:
LoggerTool.instance().debug(f"Adding message to queue: {message}")
self.MessageQueue.append(message)
LoggerTool.instance().debug(f"Message added to queue. Queue size after addition: {len(self.MessageQueue)}")
self.MessageLock.notify() # Notifies other thread
Any suggestions or advice would be greatly appreciated. Thanks in advance!
I've tried several solutions, but I haven't been able to identify the exact cause of the behavior. Since I am using SSE (Server sent events), I added the following section to the conf file but I am not sure if that is the correct way to do it: <Location /events> Header set Content-Type "text/event-stream" Header set Cache-Control "no-cache" Header set Connection "keep-alive" Header set Access-Control-Allow-Origin "*"
本文标签: Flask App Randomly Restarting When Running with Apache and modwsgiStack Overflow
版权声明:本文标题:Flask App Randomly Restarting When Running with Apache and mod_wsgi - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307969a1933496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论