python script not terminating after timeout in ZMQ recv()

Viewed 3406

This is my first time working with IPC so far and I have written this script:

#!/usr/bin/python

import zmq

context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.setsockopt(zmq.RCVTIMEO, 2000)
socket.connect ("ipc:///tmp/something")
socket.send(b"123")
try:
    message = socket.recv()
except:
    print("DEBUG!")
    message = None

When my server script is running ( it simply sends an answer ) everything is working fine.

But when the .recv()-call timeouts ( e.g. because there is no server running ), the script won't terminate after the "DEBUG!"-print and I have to manually stop it using Ctrl+C.

I tried disconnecting and closing the socket, but it doesn't change anything.

When I put the whole script into a function and call it, I get the following error on KeyboardInterrupt:

^CException ignored in: <bound method Context.__del__ of <zmq.sugar.context.Context object at 0x7f16a36d5128>>
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/zmq/sugar/context.py", line 46, in __del__
    self.term()
  File "zmq/backend/cython/context.pyx", line 136, in zmq.backend.cython.context.Context.term (zmq/backend/cython/context.c:2339)
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc (zmq/backend/cython/context.c:3207)
KeyboardInterrupt

I'm running Python 3.6.1 and version 16.0.2 of the PyZMQ module on an Arch Linux.

2 Answers
Related