kanboard / python-api-client

Python API Client for Kanboard
https://pypi.org/project/kanboard
MIT License
79 stars 26 forks source link

loop parameter default prevents causes issue in multithreaded application #19

Closed JimCircadian closed 4 years ago

JimCircadian commented 4 years ago

Hello

In the situation where the library is being imported outside of the non-__main__ thread (in this case a Flask API calling a Celery task) the event loop hasn't been initialised at time of import meaning the parameter default causes a RuntimeError

    import kanboard
  File ".../.virtualenvs/sdapi-kanban/lib/python3.6/site-packages/kanboard.py", line 38, in <module>
    class Client:
  File ".../.virtualenvs/sdapi-kanban/lib/python3.6/site-packages/kanboard.py", line 60, in Client
    loop=asyncio.get_event_loop()):
  File "/usr/lib64/python3.6/asyncio/events.py", line 694, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "/usr/lib64/python3.6/asyncio/events.py", line 602, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-4'.

I propose that the get_event_loop call should be WITHIN the constructor and optional so that the usage of asyncio for these calls is not effectively mandatory.

I'm happy to raise a pull request for this issue, and will draft one up now. Let me know if there are any questions or information you'd like me to provide.

Thanks!