mkb79 / freeletics-python

Python client for the non-publicly Freeletics API
GNU Affero General Public License v3.0
5 stars 0 forks source link

RuntimeError: There is no current event loop in thread 'MainThread'. #6

Closed jeffreywescott closed 1 year ago

jeffreywescott commented 1 year ago

In the example below, get_all_performed_trainings.py is a straight copy from the examples folder, with USERNAME, PASSWORD, and FILENAME set as appropriate.

~/dev/fl-test % python3 get_all_performed_trainings.py
Traceback (most recent call last):
  File "/Users/jeffrey/dev/fl-test/main.py", line 78, in <module>
    sync_main()
  File "/Users/jeffrey/dev/fl-test/main.py", line 43, in sync_main
    with FreeleticsClient() as client:
  File "/Users/jeffrey/Library/Python/3.9/lib/python/site-packages/freeletics/_client.py", line 26, in __init__
    self._SESSION.auth = FreeleticsAuth(
  File "/Users/jeffrey/Library/Python/3.9/lib/python/site-packages/freeletics/_auth.py", line 28, in __init__
    self._async_lock = asyncio.Lock()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/locks.py", line 81, in __init__
    self._loop = events.get_event_loop()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.

It's worth noting that the code did output a JSON file with some training data. I have no idea whether it has all of the data or not.

Other details:

~/dev/fl-test % python3 --version
Python 3.9.6
mkb79 commented 1 year ago

Thank you for reporting this issue. It seams to be a bug in setting a async lock without having an event loop.

You can use my example and remove lines 42 - 71 and 77 - 78. This would run only the async code which should work.

jeffreywescott commented 1 year ago

Commenting out just line 78 seemed to work. Thanks!