##// END OF EJS Templates
better cleanup sockets in Channels...
MinRK -
Show More
@@ -137,7 +137,23 b' class ZMQSocketChannel(Thread):'
137 terminates. :class:`RuntimeError` will be raised if
137 terminates. :class:`RuntimeError` will be raised if
138 :meth:`~threading.Thread.start` is called again.
138 :meth:`~threading.Thread.start` is called again.
139 """
139 """
140 if self.ioloop is not None:
141 self.ioloop.stop()
140 self.join()
142 self.join()
143 self.close()
144
145 def close(self):
146 if self.ioloop is not None:
147 try:
148 self.ioloop.close(all_fds=True)
149 except Exception:
150 pass
151 if self.socket is not None:
152 try:
153 self.socket.close(linger=0)
154 except Exception:
155 pass
156 self.socket = None
141
157
142 @property
158 @property
143 def address(self):
159 def address(self):
@@ -198,15 +214,6 b' class ShellChannel(ZMQSocketChannel):'
198 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
214 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
199 self.stream.on_recv(self._handle_recv)
215 self.stream.on_recv(self._handle_recv)
200 self._run_loop()
216 self._run_loop()
201 try:
202 self.socket.close()
203 except:
204 pass
205
206 def stop(self):
207 """Stop the channel's event loop and join its thread."""
208 self.ioloop.stop()
209 super(ShellChannel, self).stop()
210
217
211 def call_handlers(self, msg):
218 def call_handlers(self, msg):
212 """This method is called in the ioloop thread when a message arrives.
219 """This method is called in the ioloop thread when a message arrives.
@@ -407,15 +414,6 b' class IOPubChannel(ZMQSocketChannel):'
407 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
414 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
408 self.stream.on_recv(self._handle_recv)
415 self.stream.on_recv(self._handle_recv)
409 self._run_loop()
416 self._run_loop()
410 try:
411 self.socket.close()
412 except:
413 pass
414
415 def stop(self):
416 """Stop the channel's event loop and join its thread."""
417 self.ioloop.stop()
418 super(IOPubChannel, self).stop()
419
417
420 def call_handlers(self, msg):
418 def call_handlers(self, msg):
421 """This method is called in the ioloop thread when a message arrives.
419 """This method is called in the ioloop thread when a message arrives.
@@ -475,15 +473,6 b' class StdInChannel(ZMQSocketChannel):'
475 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
473 self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
476 self.stream.on_recv(self._handle_recv)
474 self.stream.on_recv(self._handle_recv)
477 self._run_loop()
475 self._run_loop()
478 try:
479 self.socket.close()
480 except:
481 pass
482
483 def stop(self):
484 """Stop the channel's event loop and join its thread."""
485 self.ioloop.stop()
486 super(StdInChannel, self).stop()
487
476
488 def call_handlers(self, msg):
477 def call_handlers(self, msg):
489 """This method is called in the ioloop thread when a message arrives.
478 """This method is called in the ioloop thread when a message arrives.
@@ -603,10 +592,6 b' class HBChannel(ZMQSocketChannel):'
603 # and close/reopen the socket, because the REQ/REP cycle has been broken
592 # and close/reopen the socket, because the REQ/REP cycle has been broken
604 self._create_socket()
593 self._create_socket()
605 continue
594 continue
606 try:
607 self.socket.close()
608 except:
609 pass
610
595
611 def pause(self):
596 def pause(self):
612 """Pause the heartbeat."""
597 """Pause the heartbeat."""
General Comments 0
You need to be logged in to leave comments. Login now