Created
August 13, 2012 20:08
-
-
Save turicas/3343763 to your computer and use it in GitHub Desktop.
[FIXED (not a bug)] Bug on pyzmq when trying to delete context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding: utf-8 | |
| # This is not a bug. Just need to set linger: socket.linger = 0 | |
| # You need to run it without a socket listening on *:5555 to reproduce the bug | |
| # Maybe it's related to https://github.com/zeromq/pyzmq/issues/211 and https://github.com/zeromq/pyzmq/issues/212 | |
| import zmq | |
| def zmq_bug(host_port, data, timeout=1): | |
| print 'Creating context and socket...' | |
| context = zmq.Context() | |
| connection_string = 'tcp://{}:{}'.format(*host_port) | |
| socket = context.socket(zmq.REQ) | |
| print 'Connecting...' | |
| socket.connect(connection_string) | |
| socket.linger = 0 | |
| print 'Sending JSON...' | |
| socket.send_json({'command': 'add pipeline', 'data': data}) | |
| print 'Polling...' | |
| if socket.poll(timeout): | |
| print 'Received something!' | |
| result = socket.recv() | |
| print result | |
| else: | |
| print 'Received nothing.' | |
| result = None | |
| print 'Deleting socket object...' | |
| del socket | |
| print 'Terminating context...' | |
| context.term() | |
| print 'Returning result...' | |
| return result | |
| print zmq_bug(('localhost', 5555), {'spam': 'eggs'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment