I have the following Flask app code:
def do_binance_trading(queue):
print("Going to start a socket. . .")
socket_manager = BinanceSocketManager.getInstance()
socket_manager.startSocket(queue)
print("Socket started. . .")
@app.route("/")
def main():
global process
global queue
global latestQueueData print("Ping app. . .")
if process is not None and process.is_alive():
print("App is running. Trading process id:" + str(process.pid))
# Retrieve all data from the queue
queue_data = []
while not queue.empty():
queue_data.append(queue.get())
if len(queue_data) > 0 and latestQueueData != queue_data[-1]:
latestQueueData = queue_data[-1]
# Display all data in the queue
return latestQueueData.replace("n", "<br>"), 200
else:
print("Starting App. . .")
queue = multiprocessing.Queue()
process = multiprocessing.Process(target=do_binance_trading, args=(queue,))
process.start()
print("Process started. . .")
return "Trading started", 200
if name == "main":
app.run()
The app is deployed to Azure Web Service. The logic is pretty much simple:
- Run the app. The Process starts
- On root refresh – get the stats from the queue for the process.
App is in general working fine, but from time to time, without any influence or logic, the process dies and I got the following Azure log trace:
2024-04-27T09:59:19.988977259Z Process Process-14:
2024-04-27T09:59:19.990693175Z Traceback (most recent call last):
2024-04-27T09:59:19.991752385Z File "/opt/python/3.11.7/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
2024-04-27T09:59:19.991789786Z self.run()
2024-04-27T09:59:19.991796086Z File "/opt/python/3.11.7/lib/python3.11/multiprocessing/process.py", line 108, in run
2024-04-27T09:59:19.991800386Z self._target(*self._args, **self._kwargs)
2024-04-27T09:59:19.991824686Z File "/tmp/8dc60406808a4da/app.py", line 29, in do_binance_trading
2024-04-27T09:59:19.991829486Z socket_manager.startSocket(queue)
2024-04-27T09:59:19.991832986Z File "/tmp/8dc60406808a4da/data/binance_data_socket.py", line 73, in startSocket
2024-04-27T09:59:19.991837086Z rel.dispatch()
2024-04-27T09:59:19.991840786Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/rel.py", line 228, in dispatch
2024-04-27T09:59:19.991844886Z registrar.dispatch()
2024-04-27T09:59:19.991849086Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/registrar.py", line 126, in dispatch
2024-04-27T09:59:19.991852986Z if not self.loop():
2024-04-27T09:59:19.991857186Z ^^^^^^^^^^^
2024-04-27T09:59:19.991861086Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/registrar.py", line 135, in loop
2024-04-27T09:59:19.991864786Z e = self.check_events()
2024-04-27T09:59:19.991868786Z ^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.991872386Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/registrar.py", line 300, in check_events
2024-04-27T09:59:19.991876686Z self.handle_error(fd)
2024-04-27T09:59:19.991880286Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/registrar.py", line 185, in handle_error
2024-04-27T09:59:19.991884187Z self.callback('read', fd)
2024-04-27T09:59:19.991888087Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/registrar.py", line 179, in callback
2024-04-27T09:59:19.991898687Z self.events[etype][fd].callback()
2024-04-27T09:59:19.991902887Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/rel/listener.py", line 127, in callback
2024-04-27T09:59:19.991907287Z if not self.cb(*self.args) and not self.persist and self.active:
2024-04-27T09:59:19.991924987Z ^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.991929087Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_app.py", line 515, in read
2024-04-27T09:59:19.991933287Z op_code, frame = self.sock.recv_data_frame(True)
2024-04-27T09:59:19.991936687Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.991940587Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_core.py", line 461, in recv_data_frame
2024-04-27T09:59:19.991944587Z self.pong(frame.data)
2024-04-27T09:59:19.991948187Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_core.py", line 377, in pong
2024-04-27T09:59:19.991952087Z self.send(payload, ABNF.OPCODE_PONG)
2024-04-27T09:59:19.991957087Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_core.py", line 297, in send
2024-04-27T09:59:19.991960987Z return self.send_frame(frame)
2024-04-27T09:59:19.991964487Z ^^^^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.991967987Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_core.py", line 337, in send_frame
2024-04-27T09:59:19.991971787Z l = self._send(data)
2024-04-27T09:59:19.991975087Z ^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.991978787Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_core.py", line 559, in _send
2024-04-27T09:59:19.992036988Z return send(self.sock, data)
2024-04-27T09:59:19.992043088Z ^^^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.992047388Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_socket.py", line 176, in send
2024-04-27T09:59:19.992051988Z return _send()
2024-04-27T09:59:19.992056188Z ^^^^^^^
2024-04-27T09:59:19.992060688Z File "/tmp/8dc60406808a4da/antenv/lib/python3.11/site-packages/websocket/_socket.py", line 153, in _send
2024-04-27T09:59:19.992065088Z return sock.send(data)
2024-04-27T09:59:19.992069088Z ^^^^^^^^^^^^^^^
2024-04-27T09:59:19.992073088Z File "/opt/python/3.11.7/lib/python3.11/ssl.py", line 1243, in send
2024-04-27T09:59:19.998976055Z return self._sslobj.write(data)
2024-04-27T09:59:19.998993255Z ^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-27T09:59:19.998998955Z ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2427)
The process restarts and app keeps running until another exception appears. I have a feeling that i am missing some configuration in Azure. App is configured to be “Always on”
Full app configuration:
enter image description here
tryed everything i could google on this topic with no luck
Alex Vashchenko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.