I'm attempting to poll a few sockets and a multiprocessing.Event
The documentation states:
A
zmq.Socket
or any Python object having afileno()
method that returns a valid file descriptor.
which means that I can't use my Event
but I should be able to use a file(as returned from open(...)
or an io
object (anything from the io
library), but I'm having no success:
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3\helpers\pydev\pydevd.py", line 1683, in <module> main() File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3\helpers\pydev\pydevd.py", line 1677, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3\helpers\pydev\pydevd.py", line 1087, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:\work\polldamnyou.py", line 122, in <module> p = poller.poll(1000) File "C:\WinPython-64bit-3.6.3.0Qt5\python-3.6.3.amd64\Lib\site-packages\zmq\sugar\poll.py", line 99, in poll return zmq_poll(self.sockets, timeout=timeout) File "zmq\backend\cython\_poll.pyx", line 143, in zmq.backend.cython._poll.zmq_poll File "zmq\backend\cython\_poll.pyx", line 123, in zmq.backend.cython._poll.zmq_poll File "zmq\backend\cython\checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rczmq.error.ZMQError: Unknown error
I have found the same question asked before but the solution was to use another socket which is sidestepping the problem. I am curious and want to see this working. Does any one have any clues what sort of object can be used in zmq.Poller
other than a socket?
Edit: a few things I've tried
import traceback, os, zmqdef poll(poller): try: print('polled: ', poller.poll(3)) except zmq.error.ZMQError as e: traceback.print_exc()class Pollable: def __init__(self): self.fd = os.open('dump', os.O_RDWR | os.O_BINARY) self.FD = self.fd self.events = 0 self.EVENTS = 0 self.revents = 0 self.REVENTS = 0 def fileno(self): return self.fd def __getattribute__(self, item): if item != '__class__': print("requested: ", item) return super().__getattribute__(item)ctx = zmq.Context()sock = ctx.socket(zmq.SUB)poller = zmq.Poller()poller.register(sock, zmq.POLLIN)poll(poller) # worksfile = open('dump', 'w+b')print("fileno: ", file.fileno())poller.register(file, zmq.POLLIN)poll(poller) # failsfile.events = 0file.revents = 0file.EVENTS = 0file.REVENTS = 0file.fd = file.fileno()file.FD = file.fileno()poll(poller) # still failspoller.unregister(file)file.close()poll(poller) # worksfd = os.open('dump', os.O_RDWR|os.O_BINARY)print("fd: ", fd)dummy = Pollable()poller.register(dummy, zmq.POLLIN)poll(poller) # fails
__getattribute__
shows that that fd
and fileno
are being accessed, but nothing else, so what is still wrong?!