-
Notifications
You must be signed in to change notification settings - Fork 635
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
Proactor event loop warning opt-out message is, weird? #1830
Comments
Yeah, it's still a warning because the event loop doesn't actually support what's required for zmq sockets, but pyzmq is instantiating an additional selector loop the user didn't ask for to work around that. You can suppress the warning if you are happy with this behavior. It should work, but I think it's worth the user being notified that it's happening. I think it's worth a warning because this should be considered a bug in asyncio to fail to implement basic asyncio functionality by default. There are lots of good reasons why proactor is better, but it's lacking essential basic functionality (FD reader/writer) that libzmq sockets are impossible to poll without. |
@minrk I think I understand, but when you say:
Do you mean by setting |
Sorry, no. I mean with a warnings filter. |
I think the message is wrong because it states: File "C:\Users\naseke\PycharmProjects\reedsolo.venv\Lib\site-packages\zmq\asyncio.py", line 51, in _get_selector_windows seems indicate that the tornado module is mandatory This is also not stated in the documentation: can we use zmq without zmq.asyncio in program with lib asyncio ? libzmq 4.3.5 |
The message is right, but it assumes an import. It could add the module name, though.
And rightly so. pyzmq requires tornado to be compatible with ProactorEventLoop, as stated in the error message when you try to use it without tornado:
which continues to be accurate.
Yes, you can use sync APIs just fine, but if you make a blocking call, it will block the event loop. You can combine polling intervals with s = ctx.socket(zmq.PULL)
# non-blocking recv with poll interval
async def _async_recv(s, poll_interval=0.2, timeout=5):
"""non-blocking async recv on a blocking zmq sockte"""
t = time.monotonic()
deadline = t + timeout
while True:
try:
return s.recv_multipart(zmq.DONTWAIT)
except zmq.Again:
if time.monotonic() + poll_interval >= deadline:
raise
await asyncio.sleep(poll_interval) Or you can put sockets in background threads with |
Sorry for my late response... and thank you for your response. ^_^ I'll see how to integrate it. On the other hand, what do you mean by your first sentence :
in the error message we can clearly see that it is "zmq\asyncio.py" line 51 which is trying to import tornado... it is not part of my code
Finally, if I understood correctly, the sequence is as follows:
and not :
|
Sorry, I only meant that the sample code presented: asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy()) assumes that readers can find how to import: from asyncio import WindowsSelectorEventLoopPolicy where it could avoid that assumption with: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Yes, that is correct. You can pass sockets across threads, e.g. using locks, etc. You just must make sure that they are not used concurrently across threads (e.g. not waiting in an eventloop in one thread when closed or accessed from another). But it is definitely safest to create/use/close sockets within a single thread. |
When I read this line I said to myself of course pfff ! 😅 Thank you for your time, it's clearer now 👍 😊 |
this is more suited to 'Discussion', but they're not enabled on this repo 🤔
I got this message:
pyzmq/zmq/asyncio.py
Lines 52 to 55 in 206411c
And dutifully installed
tornado
, but then I'm told:pyzmq/zmq/asyncio.py
Lines 59 to 62 in 206411c
I understand, but if I set
WindowsSelectorEventLoopPolicy()
to avoid the warning,then doesn't that defeat the purpose of installing
tornado
?... and it also causes this issue:
The text was updated successfully, but these errors were encountered: