##// END OF EJS Templates
Backport PR #4074: close Client sockets if connection fails...
MinRK -
Show More
@@ -489,7 +489,12 b' class Client(HasTraits):'
489 489 }
490 490 self._queue_handlers = {'execute_reply' : self._handle_execute_reply,
491 491 'apply_reply' : self._handle_apply_reply}
492 self._connect(sshserver, ssh_kwargs, timeout)
492
493 try:
494 self._connect(sshserver, ssh_kwargs, timeout)
495 except:
496 self.close(linger=0)
497 raise
493 498
494 499 # last step: setup magics, if we are in IPython:
495 500
@@ -593,7 +598,6 b' class Client(HasTraits):'
593 598 self._connected=True
594 599
595 600 def connect_socket(s, url):
596 # url = util.disambiguate_url(url, self._config['location'])
597 601 if self._ssh:
598 602 return tunnel.tunnel_connection(s, url, sshserver, **ssh_kwargs)
599 603 else:
@@ -950,14 +954,23 b' class Client(HasTraits):'
950 954 view.activate(suffix)
951 955 return view
952 956
953 def close(self):
957 def close(self, linger=None):
958 """Close my zmq Sockets
959
960 If `linger`, set the zmq LINGER socket option,
961 which allows discarding of messages.
962 """
954 963 if self._closed:
955 964 return
956 965 self.stop_spin_thread()
957 snames = filter(lambda n: n.endswith('socket'), dir(self))
958 for socket in map(lambda name: getattr(self, name), snames):
959 if isinstance(socket, zmq.Socket) and not socket.closed:
960 socket.close()
966 snames = [ trait for trait in self.trait_names() if trait.endswith("socket") ]
967 for name in snames:
968 socket = getattr(self, name)
969 if socket is not None and not socket.closed:
970 if linger is not None:
971 socket.close(linger=linger)
972 else:
973 socket.close()
961 974 self._closed = True
962 975
963 976 def _spin_every(self, interval=1):
General Comments 0
You need to be logged in to leave comments. Login now