erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.83k stars 765 forks source link

examples/tk.py fails with "RuntimeError: Cannot run the event loop while another loop is running" #243

Closed drusakov778 closed 4 years ago

drusakov778 commented 4 years ago

Hi Ewald,

seems to be very nice library which I am starting to use now. Running the examples with single modification of my local host, port, and client_id in the IB.connect() line.

examples/qt_ticker_table.py runs fine

examples/tk.py fails:

rusakov@dfk78:~/mcai/github/ib_insync (master)$ python examples/tk.py 
Traceback (most recent call last):
  File "examples/tk.py", line 47, in <module>
    app.run()
  File "examples/tk.py", line 36, in run
    self.loop.run_forever()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 531, in run_forever
    self._check_runnung()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 526, in _check_runnung
    'Cannot run the event loop while another loop is running')
RuntimeError: Cannot run the event loop while another loop is running

MacOS: 10.14.6 Python 3.7.7 ib_insync: latest, installed from git, hash f4e0525 nest-asyncio: 1.3.2 eventkit: 0.8.6

drusakov778 commented 4 years ago

related discussion with some more info: https://groups.io/g/insync/topic/71373406

erdewit commented 4 years ago

More folks are having the issue, but I can't reproduce it.

Not sure what other loop could be running.

erdewit commented 4 years ago

There's a typo in the Python 3.7 source code: self._check_runnung() which was not handled in nest_asyncio. Version 1.3.3 of nest_asyncio addresses this.

drusakov778 commented 4 years ago

Ewald, impressive, thank you. Will check tomorrow and confirm from my side.

drusakov778 commented 4 years ago

confirmed. fix works for me for python 3.7.7. Thank you

erdewit commented 4 years ago

Great, thanks for confirming