Skip to content

Commit

Permalink
Fix websocket multiprocessing.manager.Queue issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed May 13, 2024
1 parent d5c79e6 commit 3acd768
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion panther/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from panther.main import Panther # noqa: F401

__version__ = '4.2.1'
__version__ = '4.2.2'


def version():
Expand Down
14 changes: 9 additions & 5 deletions panther/base_websocket.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

import asyncio
import logging
import orjson as json
from multiprocessing.managers import SyncManager
from typing import TYPE_CHECKING, Literal

import orjson as json

import logging
from panther import status
from panther.base_request import BaseRequest
from panther.configs import config
Expand Down Expand Up @@ -53,9 +52,14 @@ async def __call__(self):
logger.info("Subscribed to 'websocket_connections' queue")
while True:
try:
received_message = queue.get()
received_message = await asyncio.to_thread(queue.get)
if received_message is None:
# The None came from the CancelledError, so break the loop
break
await self._handle_received_message(received_message=received_message)
except InterruptedError:
except (InterruptedError, asyncio.CancelledError):
# Put the None to the queue, so the executor knows that it ends
queue.put(None)
break
else:
# We have a redis connection, so use it for pubsub
Expand Down

0 comments on commit 3acd768

Please sign in to comment.