Skip to content

Commit 7569a4b

Browse files
committed
Raise an exception if the loop is the wrong type on Windows
Fixes: #86 Closes: #105
1 parent 414b525 commit 7569a4b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ The API is pretty simple, three functions are provided in the ``DNSResolver`` cl
5555
``ARES_ECANCELLED`` errno.
5656

5757

58+
Note for Windows users
59+
======================
60+
61+
This library requires the asyncio loop to be a `SelectorEventLoop`, which is not the default on Windows since
62+
Python 3.8.
63+
64+
The default can be changed as follows (do this very early in your application):
65+
66+
.. code:: python
67+
68+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
69+
70+
This may have other implications for the rest of your codebase, so make sure to test thoroughly.
71+
72+
5873
Running the test suite
5974
======================
6075

aiodns/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import functools
44
import pycares
55
import socket
6+
import sys
67

78
from typing import (
89
Any,
9-
List,
1010
Optional,
1111
Set,
1212
Sequence
@@ -50,6 +50,10 @@ def __init__(self, nameservers: Optional[Sequence[str]] = None,
5050
**kwargs: Any) -> None:
5151
self.loop = loop or asyncio.get_event_loop()
5252
assert self.loop is not None
53+
if sys.platform == 'win32':
54+
if not isinstance(self.loop, asyncio.SelectorEventLoop):
55+
raise RuntimeError(
56+
'aiodns needs a SelectorEventLoop on Windows. See more: https://github.com/saghul/aiodns/issues/86')
5357
kwargs.pop('sock_state_cb', None)
5458
self._channel = pycares.Channel(sock_state_cb=self._sock_state_cb, **kwargs)
5559
if nameservers:

0 commit comments

Comments
 (0)