zeromq/pyzmq — Issue #160: pyzmq hard locks Windows 7 with fast socket open/close
Author: kyledj
Created: 2011-12-14 17:19:55+00:00
State: open

Found this out the hard way with some buggy code that used to work "fine" on a Windows XP box.

This is probably a libzmq issue, and not specifically a pyzmq issue, but I have never written any C which uses libzmq, so am not sure how to recreate it. I thought I would post it here for anyone who encounters the issue.

While the code below is not ideal, (like I said, it was found in something buggy), it seems it shouldn't be able to hard lock the machine. I have been able to lock up the client with a sleep of one to five seconds between sockets occasionally as well, though inconsistently.

## Example Server
```python
import zmq

def run():
ctx = zmq.Context()

sock = ctx.socket(zmq.REP)
sock.bind('tcp://127.0.0.1:5555')

print "Waiting..."
while True:
msg = sock.recv()
sock.send('10-4')
print msg

if __name__ == '__main__':
run()
```

## Example Client
```python
import zmq

def connect_and_send(ctx, msg):
sock = ctx.socket(zmq.REQ)
sock.connect('tcp://127.0.0.1:5555')
sock.send(msg)
sock.recv()
sock.close()

def run():
ctx = zmq.Context()

count = 1
while True:
connect_and_send(ctx, "Msg %s" % count)
count += 1

if __name__ == '__main__':
run()
```