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

Issue with loop on Windows platform (NotImplementedError) #678

Open
XCanG opened this issue Apr 28, 2020 · 1 comment
Open

Issue with loop on Windows platform (NotImplementedError) #678

XCanG opened this issue Apr 28, 2020 · 1 comment

Comments

@XCanG
Copy link

XCanG commented Apr 28, 2020

I have issue with connection to DB on Windows on code, which work on Linux.
After some research it looks like issue related to Windows what use SelectorEventLoop and it should be replaced to ProactorEventLoop. (check this stackoverflow post)

Traceback for my issue:

Traceback (most recent call last):
  File "run_test.py", line 43, in <module>
    asyncio.run(Notifier(**data))
  File "C:\Program Files\Python38\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "C:\Users\X4\git\massenders\app\core\notifier.py", line 316, in ppr
    clientManager: ClientManager = await ManagersDi.clientDataManager()
  File "C:\Users\X4\git\massenders\app\core\di.py", line 56, in get_ClientManager
    return ClientManager(await DBDi.mdbPool())
  File "C:\Users\X4\git\massenders\app\core\di.py", line 30, in get_mdb_connection
    return await aiopg.create_pool(mdb_dns, minsize=5, maxsize=30)
  File "C:\Program Files\Python38\lib\site-packages\aiopg\pool.py", line 155, in from_pool_fill
    await self._fill_free_pool(False)
  File "C:\Program Files\Python38\lib\site-packages\aiopg\pool.py", line 193, in _fill_free_pool
    conn = await connect(
  File "C:\Program Files\Python38\lib\site-packages\aiopg\connection.py", line 38, in connect
    coro = Connection(
  File "C:\Program Files\Python38\lib\site-packages\aiopg\connection.py", line 92, in __init__
    self._loop.add_reader(self._fileno, self._ready, self._weakref)
  File "C:\Program Files\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
Exception ignored in: <function Connection.__del__ at 0x0000020AF0118F70>
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\site-packages\aiopg\connection.py", line 512, in __del__
  File "C:\Program Files\Python38\lib\site-packages\aiopg\connection.py", line 310, in close
  File "C:\Program Files\Python38\lib\site-packages\aiopg\connection.py", line 285, in _close
  File "C:\Program Files\Python38\lib\asyncio\events.py", line 504, in remove_reader
NotImplementedError:

The problem with aiopg\connection.py in self._loop.add_reader(self._fileno, self._ready, self._weakref) which referred to asyncio\events.py where all class AbstractEventLoop have NotImplementedError:

    def add_reader(self, fd, callback, *args):
        raise NotImplementedError

    def remove_reader(self, fd):
        raise NotImplementedError

and because there used direct methods (self._loop.add_reader) I can't make quick workaround to make code works. There need some implementation when Windows platform is used.

It is also referenced in documentation note:

returns the running loop asyncio.AbstractEventLoop

Is it possible to add support of asyncio.ProactorEventLoop()?

@akeeman
Copy link

akeeman commented Aug 3, 2020

Quick workaround is to add this to your code (ref)

import sys, asyncio

if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

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

2 participants