saghul / aiodns

Simple DNS resolver for asyncio

Home Page:https://pypi.python.org/pypi/aiodns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NotImplementedError on Win10 x64 OS

shmilylty opened this issue · comments

Env

Win10 19.09 x64
Python 3.8.0

Code

import aiodns
import asyncio

async def query_a(name):
    resolver = aiodns.DNSResolver()
    return await resolver.query(name, "A")

if __name__ == '__main__':
    res = asyncio.run(query_a('qq.com'), debug=True)
    pass

Error

Connected to pydev debugger (build 193.5662.61)
From cffi callback <function _sock_state_cb at 0x000001C25B3C3430>:
Traceback (most recent call last):
  File "C:\Users\test\.virtualenvs\OneForAll-qYrK1GZO\lib\site-packages\pycares\__init__.py", line 91, in _sock_state_cb
    sock_state_cb(socket_fd, readable, writable)
  File "C:\Users\test\.virtualenvs\OneForAll-qYrK1GZO\lib\site-packages\aiodns\__init__.py", line 104, in _sock_state_cb
    self.loop.add_reader(fd, self._handle_event, fd, READ)
  File "C:\Program Files\Python38\Lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
commented

Add asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) in top of file
couse python3.8 add Proactor loop in asyncio and broke compatability

Add asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) in top of file
couse python3.8 add Proactor loop in asyncio and broke compatability

But I want to use proactor loop,have any idea plz?

commented

So add it explicitly

import aiodns
import asyncio

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def query_a(name):
    resolver = aiodns.DNSResolver()
    return await resolver.query(name, "A")

if __name__ == '__main__':
    res = asyncio.run(query_a('qq.com'))
    

So add it explicitly

import aiodns
import asyncio

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def query_a(name):
    resolver = aiodns.DNSResolver()
    return await resolver.query(name, "A")

if __name__ == '__main__':
    res = asyncio.run(query_a('qq.com'))
    

I mean,use ProactorEventLoop,not use SelectorEventLoop.

https://docs.python.org/3.8/library/asyncio-platforms.html#asyncio-platform-support

ProactorEventLoop has the following limitations:

The loop.add_reader() and loop.add_writer() methods are not supported.

We depend on the add_reader / add_writer APIs for integrating with c-ares.