From 779d96f1ef786aeb5c61720ab27e47b0acf44cd5 2014-05-01 23:06:59 From: MinRK Date: 2014-05-01 23:06:59 Subject: [PATCH] cleanup socket cleanup - set linger on sockets (avoid hang on exit) - actually close sockets, not just zmq streams (blame pyzmq, aka me) seems to be necessary for js/notebook/shutdown test to avoid hanging on Python 3.4. --- diff --git a/IPython/html/services/kernels/handlers.py b/IPython/html/services/kernels/handlers.py index 605e9e6..041ffce 100644 --- a/IPython/html/services/kernels/handlers.py +++ b/IPython/html/services/kernels/handlers.py @@ -127,7 +127,10 @@ class ZMQChannelHandler(AuthenticatedZMQStreamHandler): # closed before the ZMQ streams are setup, they could be None. if self.zmq_stream is not None and not self.zmq_stream.closed(): self.zmq_stream.on_recv(None) + # close the socket directly, don't wait for the stream + socket = self.zmq_stream.socket self.zmq_stream.close() + socket.close() class IOPubHandler(ZMQChannelHandler): diff --git a/IPython/kernel/connect.py b/IPython/kernel/connect.py index 386f80d..a6b8b6d 100644 --- a/IPython/kernel/connect.py +++ b/IPython/kernel/connect.py @@ -524,6 +524,8 @@ class ConnectionFileMixin(Configurable): socket_type = channel_socket_types[channel] self.log.debug("Connecting to: %s" % url) sock = self.context.socket(socket_type) + # set linger to 1s to prevent hangs at exit + sock.linger = 1000 if identity: sock.identity = identity sock.connect(url)