Skip to content

Commit

Permalink
Fix loop isolation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Jul 30, 2022
1 parent 590000a commit a752998
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/perspective/perspective/handlers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import asyncio
from abc import ABC, abstractmethod
import functools

from ..core.exception import PerspectiveError

Expand Down Expand Up @@ -58,10 +59,8 @@ def check_origin(self, origin):
"""
return self._check_origin

def _session_callback(self, *args, **kwargs):
return asyncio.run_coroutine_threadsafe(
self.post(*args, **kwargs), asyncio.get_event_loop()
)
def _session_callback(self, loop, *args, **kwargs):
return asyncio.run_coroutine_threadsafe(self.post(*args, **kwargs), loop)

async def on_message(self, message):
"""When the websocket receives a message, send it to the :obj:`process`
Expand All @@ -73,7 +72,8 @@ async def on_message(self, message):
await self.post("pong")
return

self._session.process(message, self._session_callback)
loop = asyncio.get_event_loop()
self._session.process(message, functools.partial(self._session_callback, loop))

async def post(self, message, binary=False):
"""When `post` is called by `PerspectiveManager`, serialize the data to
Expand Down

0 comments on commit a752998

Please sign in to comment.