示例#1
0
 def reconnect_init(self, connection):
     for m in Protocol.reconnect_init(self, connection):
         yield m
     connection.xid = ord(os.urandom(1)) + 1
     connection.zookeeper_requests = {}
     connection.zookeeper_handshake = False
     connection.zookeeper_lastzxid = 0
     for m in connection.waitForSend(ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.UP,
                                                                   connection,
                                                                   connection.connmark,
                                                                   self)):
         yield m
示例#2
0
文件: zookeeper.py 项目: versee/vlcp
 def reconnect_init(self, connection):
     for m in Protocol.reconnect_init(self, connection):
         yield m
     connection.xid = ord(os.urandom(1)) + 1
     connection.zookeeper_requests = {}
     connection.zookeeper_handshake = False
     connection.zookeeper_lastzxid = 0
     for m in connection.waitForSend(
             ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.UP,
                                           connection, connection.connmark,
                                           self)):
         yield m
示例#3
0
文件: console.py 项目: dq5070410/vlcp
 def _intercept_main(self):
     cr = self.apiroutine.currentroutine
     self.sendEventQueue = Queue()
     _console_connect_event = threading.Event()
     _console_connect_event.clear()
     for m in self.apiroutine.waitForSend(ConsoleEvent('initproxy')):
         yield m
     if not self.startinconsole:
         p = Protocol()
         p.persist = True
         p.createqueue = False
         def init(connection):
             sock = connection.socket
             self.telnet_socket = sock
             self.scheduler.unregisterPolling(connection.socket)
             connection.socket = None
             connection.connected = False
             _console_connect_event.set()
             yield (SocketInjectDone.createMatcher(sock),)
         p.init = init
         p.reconnect_init = init
         Client(self.telnetconsole, p, self.scheduler, self.key, self.certificate, self.ca_certs).start()
     def syscall_threaded_main(scheduler, processor):
         # Detach self
         scheduler.unregisterall(cr)
         self._threaded_main_quit = False
         def threaded_main():
             try:
                 scheduler.main(False, False)
             finally:
                 self._threaded_main_quit = True
                 _console_connect_event.set()
         t = threading.Thread(target=threaded_main)
         t.daemon = True
         t.start()
         try:
             if self.startinconsole:
                 self._interactive()
             else:
                 while not self._threaded_main_quit:
                     try:
                         while not _console_connect_event.is_set():
                             # There is a bug in Python 2.x that wait without timeout cannot be
                             # interrupted by signal
                             _console_connect_event.wait(3600)
                         if self._threaded_main_quit:
                             break
                     except InterruptedBySignalException:
                         # This signal should interrupt the poller, but poller is not in the main thread
                         # Send an event through the proxy will do the trick
                         self.sendEventQueue.put((InterruptPoller(),))
                         continue
                     pstdin_r, pstdin_w = os.pipe()
                     pstdout_r, pstdout_w = os.pipe()
                     orig_stdin = sys.stdin
                     orig_stdout = sys.stdout
                     orig_stderr = sys.stderr
                     try:
                         pstdin = os.fdopen(pstdin_r, 'rU', 0)
                         pstdout = os.fdopen(pstdout_w, 'w', 0)
                         sys.stdin = pstdin
                         sys.stdout = pstdout
                         sys.stderr = pstdout
                         sock = self.telnet_socket
                         sock.setblocking(True)
                         self.telnet_socket = None
                         _console_connect_event.clear()
                         t = threading.Thread(target=self._telnet_server, args=(pstdin_w, pstdout_r, sock, orig_stdout))
                         t.daemon = True
                         t.start()
                         try:
                             self._interactive()
                         except SystemExit:
                             pass
                         if not t.is_alive():
                             break
                         self.sendEventQueue.put((SocketInjectDone(sock),))
                     finally:
                         try:
                             sock.shutdown(socket.SHUT_RDWR)
                         except:
                             pass
                         try:
                             pstdin.close()
                         except:
                             pass
                         try:
                             pstdout.close()
                         except:
                             pass
                         sys.stdin = orig_stdin
                         sys.stdout = orig_stdout
                         sys.stderr = orig_stderr
         except SystemExit:
             pass
         finally:
             self.sendEventQueue.put(None)
             scheduler.quit()
             if self.startinconsole:
                 print('Wait for scheduler end, this may take some time...')
             t.join()
     for m in self.apiroutine.syscall(syscall_threaded_main, True):
         yield m
示例#4
0
    def _intercept_main(self):
        cr = self.apiroutine.currentroutine
        self.sendEventQueue = Queue()
        _console_connect_event = threading.Event()
        _console_connect_event.clear()
        for m in self.apiroutine.waitForSend(ConsoleEvent('initproxy')):
            yield m
        if not self.startinconsole:
            p = Protocol()
            p.persist = True
            p.createqueue = False

            def init(connection):
                sock = connection.socket
                self.telnet_socket = sock
                self.scheduler.unregisterPolling(connection.socket)
                connection.socket = None
                connection.connected = False
                _console_connect_event.set()
                yield (SocketInjectDone.createMatcher(sock), )

            p.init = init
            p.reconnect_init = init
            Client(self.telnetconsole, p, self.scheduler, self.key,
                   self.certificate, self.ca_certs).start()

        def syscall_threaded_main(scheduler, processor):
            # Detach self
            scheduler.unregisterall(cr)
            self._threaded_main_quit = False

            def threaded_main():
                try:
                    scheduler.main(False, False)
                finally:
                    self._threaded_main_quit = True
                    _console_connect_event.set()

            t = threading.Thread(target=threaded_main)
            t.daemon = True
            t.start()
            try:
                if self.startinconsole:
                    self._interactive()
                else:
                    while not self._threaded_main_quit:
                        try:
                            while not _console_connect_event.is_set():
                                # There is a bug in Python 2.x that wait without timeout cannot be
                                # interrupted by signal
                                _console_connect_event.wait(3600)
                            if self._threaded_main_quit:
                                break
                        except InterruptedBySignalException:
                            # This signal should interrupt the poller, but poller is not in the main thread
                            # Send an event through the proxy will do the trick
                            self.sendEventQueue.put((InterruptPoller(), ))
                            continue
                        pstdin_r, pstdin_w = os.pipe()
                        pstdout_r, pstdout_w = os.pipe()
                        orig_stdin = sys.stdin
                        orig_stdout = sys.stdout
                        orig_stderr = sys.stderr
                        try:
                            pstdin = os.fdopen(pstdin_r, 'rU', 0)
                            pstdout = os.fdopen(pstdout_w, 'w', 0)
                            sys.stdin = pstdin
                            sys.stdout = pstdout
                            sys.stderr = pstdout
                            sock = self.telnet_socket
                            sock.setblocking(True)
                            self.telnet_socket = None
                            _console_connect_event.clear()
                            t = threading.Thread(target=self._telnet_server,
                                                 args=(pstdin_w, pstdout_r,
                                                       sock, orig_stdout))
                            t.daemon = True
                            t.start()
                            try:
                                self._interactive()
                            except SystemExit:
                                pass
                            if not t.is_alive():
                                break
                            self.sendEventQueue.put((SocketInjectDone(sock), ))
                        finally:
                            try:
                                sock.shutdown(socket.SHUT_RDWR)
                            except:
                                pass
                            try:
                                pstdin.close()
                            except:
                                pass
                            try:
                                pstdout.close()
                            except:
                                pass
                            sys.stdin = orig_stdin
                            sys.stdout = orig_stdout
                            sys.stderr = orig_stderr
            except SystemExit:
                pass
            finally:
                self.sendEventQueue.put(None)
                scheduler.quit()
                if self.startinconsole:
                    print('Wait for scheduler end, this may take some time...')
                t.join()

        for m in self.apiroutine.syscall(syscall_threaded_main, True):
            yield m