I get strange system behavior when using an instance of PyZMQ IOLoop:
def main():
context = zmq.Context()
s = context.socket(zmq.REP)
s.bind('tcp://*:12345')
stream = zmqstream.ZMQStream(s)
stream.on_recv(on_message)
io_loop = ioloop.IOLoop.instance()
io_loop.add_handler(some_file.fileno(), on_file_data_ready_read_and_then_write, io_loop.READ)
io_loop.add_timeout(time.time() + 10, another_handler)
io_loop.start()
def on_file_data_ready_read_and_then_write(fd, events):
some_file.read()
print "Read content"
some_file.write("blah")
print "Wrote content"
def on_message(msg):
pass
if __name__=='__main__':
main()
Basically, the event loop listens on zmq port 12345 for JSON requests and reads the contents from the file when it is available (and when it does, manipulates it and copies it back). Basically, the file is a special module / proc / kernel module that was built for this).
Everything works well, but for some reason, looking at strace, I see the following:
...
1. read(\23424) <--- Content read from file
2. write("read content")
3. write("Wrote content")
4. POLLING
5. write(\324324)
...
So it looks like the writing to the file was not done in the order of the python script, but the system call to writing to this file was done AFTER the polling, although this should have been done between lines 2 and 3.
Any ideas?
Joel source
share