Windows 10 - RuntimeError: Event loop is closed and UnicodeEncodeError: 'charmap' codec can't encode character
See original GitHub issueNot a bug, but perhaps it should be mentioned that databay will not work with Windows 10 due to a bug or the way asyncio chooses the default event loop mechanism, which throws an error, instead of just a warning.
So if running asyncio-dependent code on Windows machine, you will get an error similar below:
Traceback (most recent call last):
File "C:\Programs\Python38\lib\asyncio\proactor_events.py", line 95, in __del__
self.close()
File "C:\Programs\Python38\lib\asyncio\proactor_events.py", line 86, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Programs\Python38\lib\asyncio\base_events.py", line 683, in call_soon
self._check_closed()
File "C:\Programs\Python38\lib\asyncio\base_events.py", line 475, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Per this SO question, possible workaround is to use asyncio loop’s run_until_complete()
instead of just run()
(Update 1 by Voy - added more info)
To Reproduce Example code (blockchain example):
import datetime
from databay.inlets import HttpInlet
from databay.outlets import PrintOutlet
from databay import Link
from databay.planners import APSPlanner
stock_inlet = HttpInlet('https://blockchain.info/ticker')
print_outlet = PrintOutlet(True, True)
link = Link(stock_inlet, print_outlet, interval=datetime.timedelta(seconds=1))
planner = APSPlanner(link)
planner.start()
Environment Databay version: 0.1.2 Python version: 3.8.2 OS: Ubuntu 20.04 and Windows 10
(Update 2 by Voy - explaining the true issue)
The RuntimeError: Event loop is closed
is only half of the problem here, and in fact is not the cause for the code to stop working, but a side effect happening when program terminates and can be fixed easily. The code wouldn’t execute due to UnicodeEncodeError
, which we figure out later down the line.
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (12 by maintainers)
Top GitHub Comments
@Voyz Well good news! Finally, got the blockchain_demo.py working.
Added:
to the top of my local copy of config.py
and then at the terminal, executed:
Then executed the blockchain_demo.py:
EDIT: It appears you don’t need to issue the
chcp 65001
command, just setting the PYTHONIOENCODING environment variable toutf-8
took care of the encoding issue.Fantastic you managed to figure this one out! Thanks for following up with the explanation - that explains everything. I nonetheless added a warning should someone have that encoding set incorrectly, as this may cause unexpected behaviour without being very verbose.