Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async lock error #119

Closed
smallevilbeast opened this issue Dec 2, 2022 · 1 comment
Closed

async lock error #119

smallevilbeast opened this issue Dec 2, 2022 · 1 comment

Comments

@smallevilbeast
Copy link

        _client.on('event_server_push', self._on_server_push)
  File "E:\public_project\imchat-new\venv\lib\site-packages\pyee\base.py", line 77, in on
    return self.add_listener(event, f)
  File "E:\public_project\imchat-new\venv\lib\site-packages\pyee\base.py", line 108, in add_listener
    self._add_event_handler(event, f, f)
  File "E:\public_project\imchat-new\venv\lib\site-packages\pyee\base.py", line 113, in _add_event_handler
    self.emit("new_listener", event, k)
  File "E:\public_project\imchat-new\venv\lib\site-packages\pyee\base.py", line 176, in emit
    handled = self._call_handlers(event, args, kwargs)
  File "E:\public_project\imchat-new\venv\lib\site-packages\pyee\base.py", line 151, in _call_handlers
    with self._lock:
  File "E:\public_project\imchat-new\venv\lib\site-packages\tornado\locks.py", line 553, in __enter__
    raise RuntimeError("Use `async with` instead of `with` for Lock")
RuntimeError: Use `async with` instead of `with` for Lock
@smallevilbeast
Copy link
Author

example:

import pyee
import asyncio
from asyncio.locks import Lock


class Demo(pyee.AsyncIOEventEmitter):
    def __init__(self):
        super().__init__()
        self._lock = Lock()

    async def get_seq(self):
        async with self._lock:
            return 1

    async def send(self):
        seq = await self.get_seq()
        self.emit('event_test')


class LockTest(pyee.AsyncIOEventEmitter):
    def __init__(self):
        super().__init__()

        self._demo = Demo()
        self._demo.on('event_test', self._on_event_test)

    async def _on_event_test(self):
        print('_on_event_test')

    async def send(self):
        await self._demo.send()


async def run():
    test = LockTest()
    await test.send()


if __name__ == '__main__':
    asyncio.run(run())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant