1 """A thread for a control channel.""" 2 from threading import Thread 3 4 from tornado.ioloop import IOLoop 5 6 CONTROL_THREAD_NAME = "Control" 7 8 9 class ControlThread(Thread): 10 """A thread for a control channel.""" 11 12 def __init__(self, **kwargs): 13 """Initialize the thread.""" 14 Thread.__init__(self, name=CONTROL_THREAD_NAME, **kwargs) 15 self.io_loop = IOLoop(make_current=False) 16 self.pydev_do_not_trace = True 17 self.is_pydev_daemon_thread = True 18 19 def run(self): 20 """Run the thread.""" 21 self.name = CONTROL_THREAD_NAME 22 try: 23 self.io_loop.start() 24 finally: 25 self.io_loop.close() 26 27 def stop(self): 28 """Stop the thread. 29 30 This method is threadsafe. 31 """ 32 self.io_loop.add_callback(self.io_loop.stop) 33