diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index 092272e..ff9ecaa 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -599,7 +599,6 @@ class Client(HasTraits): self._connected=True def connect_socket(s, url): - # url = util.disambiguate_url(url, self._config['location']) if self._ssh: return tunnel.tunnel_connection(s, url, sshserver, **ssh_kwargs) else: @@ -956,14 +955,23 @@ class Client(HasTraits): view.activate(suffix) return view - def close(self): + def close(self, linger=None): + """Close my zmq Sockets + + If `linger`, set the zmq LINGER socket option, + which allows discarding of messages. + """ if self._closed: return self.stop_spin_thread() - snames = filter(lambda n: n.endswith('socket'), dir(self)) - for socket in map(lambda name: getattr(self, name), snames): - if isinstance(socket, zmq.Socket) and not socket.closed: - socket.close() + snames = [ trait for trait in self.trait_names() if trait.endswith("socket") ] + for name in snames: + socket = getattr(self, name) + if socket is not None and not socket.closed: + if linger is not None: + socket.close(linger=linger) + else: + socket.close() self._closed = True def _spin_every(self, interval=1):