Esempio n. 1
0
        def Pump(stream):
            queue = py_queue.Queue()
            
            def rdr():
                logger.debug('START RDR')
                while True:
                    buf = process.stdout.read(1)
                    if buf:
                        queue.put( buf )
                    else: 
                        queue.put( None )
                        break
                logger.debug('END RDR')
                queue.put( None )
                time.sleep(1)
                
            def clct():
                active = True
                logger.debug('START clct')
                while active:
                    r = queue.get()
                    if r is None:
                        break
                    try:
                        while True:
                            r1 = queue.get(timeout=0.005)
                            if r1 is None:
                                active = False
                                break
                            else:
                                r += r1
                    except:
                        pass
                    if r is not None:
                        if app.config['config']['is_py2']:
                            try:
                                r = r.decode('utf-8')
                            except Exception as exception: 
                                #logger.error('Exception:%s', exception)
                                #logger.error(traceback.format_exc())
                                try:
                                    r = r.decode('cp949')
                                except Exception as exception: 
                                    logger.error('Exception:%s', exception)
                                    logger.error(traceback.format_exc())
                                    try:
                                        r = r.decode('euc-kr')
                                    except:
                                        pass
                        #logger.debug('IN:%s', r)
                        #logger.debug('IN2:%s', r.replace('\x00', ''))
                        LogicNormal.command_queue.put(r.replace('\x00', ''))
                        

                LogicNormal.command_queue.put('<END>')
                logger.debug('END clct')
            for tgt in [rdr, clct]:
                th = threading.Thread(target=tgt)
                th.setDaemon(True)
                th.start()
Esempio n. 2
0
 def queue_start(self):
     try:
         if self.download_queue is None:
             self.download_queue = py_queue.Queue()
         if self.download_thread is None:
             self.download_thread = threading.Thread(target=self.download_thread_function, args=())
             self.download_thread.daemon = True  
             self.download_thread.start()
     except Exception as exception: 
         self.P.logger.error('Exception:%s', exception)
         self.P.logger.error(traceback.format_exc())
Esempio n. 3
0
    def queue_start():
        try:
            if LogicQueue.download_queue is None:
                LogicQueue.download_queue = py_queue.Queue()

            if LogicQueue.download_thread is None:
                LogicQueue.download_thread = threading.Thread(
                    target=LogicQueue.download_thread_function, args=())
                LogicQueue.download_thread.daemon = True
                LogicQueue.download_thread.start()
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Esempio n. 4
0
    def start():
        try:
            if TvingProgram.download_queue is None:
                TvingProgram.download_queue = py_queue.Queue()

            if TvingProgram.download_thread is None:
                TvingProgram.download_thread = threading.Thread(
                    target=TvingProgram.download_thread_function, args=())
                TvingProgram.download_thread.daemon = True
                TvingProgram.download_thread.start()
        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Esempio n. 5
0
 def start_communicate_load():
     LogicNormal.command_queue = py_queue.Queue()
     def func():
         position = 0
         flag = True
         while LogicNormal.command_queue is not None:
             if sys.version_info[0] == 2: 
                 logs = LogicNormal.load_log_list.get_log()
                 if logs:
                     for log in logs:
                         LogicNormal.command_queue.put(log.strip() + '\n')
             else:
                 logs = LogicNormal.load_log_list.getvalue()
                 LogicNormal.load_log_list.truncate(0)
                 if logs:
                     LogicNormal.command_queue.put(logs.strip() + '\n')
             
             time.sleep(1)
     th = threading.Thread(target=func)
     th.setDaemon(True)
     th.start()
Esempio n. 6
0
    def start_communicate(self, current_command, show_command=True):
        self.stdout_queue = py_queue.Queue()
        if show_command:
            self.stdout_queue.put('$ %s\n' % ' '.join(current_command))
        sout = io.open(self.process.stdout.fileno(), 'rb', closefd=False)

        #serr = io.open(process.stderr.fileno(), 'rb', closefd=False)

        def Pump(stream):
            queue = py_queue.Queue()

            def rdr():
                #logger.debug('START RDR')
                while True:
                    buf = self.process.stdout.read(1)
                    if buf:
                        queue.put(buf)
                    else:
                        queue.put(None)
                        break
                #logger.debug('END RDR')
                queue.put(None)
                time.sleep(1)

                #Logic.command_close()
            def clct():
                active = True
                #logger.debug('START clct')
                while active:
                    r = queue.get()
                    if r is None:
                        break
                    try:
                        while True:
                            r1 = queue.get(timeout=0.005)
                            if r1 is None:
                                active = False
                                break
                            else:
                                r += r1
                    except:
                        pass
                    if r is not None:
                        if app.config['config']['is_py2']:
                            try:
                                r = r.decode('utf-8')
                            except Exception as exception:
                                #logger.error('Exception:%s', e)
                                #logger.error(traceback.format_exc())
                                try:
                                    r = r.decode('cp949')
                                except Exception as exception:
                                    logger.error('Exception:%s', exception)
                                    logger.error(traceback.format_exc())
                                    try:
                                        r = r.decode('euc-kr')
                                    except:
                                        pass

                        self.stdout_queue.put(r)
                        self.return_log += r.split('\n')
                        #logger.debug('IN:%s', r)
                self.stdout_queue.put('<END>')
                #logger.debug('END clct')
                #Logic.command_close()

            for tgt in [rdr, clct]:
                th = threading.Thread(target=tgt)
                th.setDaemon(True)
                th.start()

        Pump(sout)
Esempio n. 7
0
        def Pump(stream):
            queue = py_queue.Queue()

            def rdr():
                logger.debug('START RDR')
                while True:
                    buf = SystemLogicCommand.process.stdout.read(1)
                    if buf:
                        queue.put(buf)
                    else:
                        queue.put(None)
                        break
                logger.debug('END RDR')
                queue.put(None)
                time.sleep(1)

                #Logic.command_close()
            def clct():
                active = True
                logger.debug('START clct')
                while active:
                    r = queue.get()
                    if r is None:
                        break
                    try:
                        while True:
                            r1 = queue.get(timeout=0.005)
                            if r1 is None:
                                active = False
                                break
                            else:
                                r += r1
                    except:
                        pass
                    if r is not None:
                        try:
                            r = r.decode('utf-8')
                        except Exception as exception:
                            #logger.error('Exception:%s', e)
                            #logger.error(traceback.format_exc())
                            try:
                                r = r.decode('cp949')
                            except Exception as exception:
                                logger.error('Exception:%s', exception)
                                logger.error(traceback.format_exc())
                                try:
                                    r = r.decode('euc-kr')
                                except:
                                    pass

                        SystemLogicCommand.stdout_queue.put(r)
                        #SystemLogicCommand.return_log.append(r)
                        SystemLogicCommand.return_log += r.split('\n')
                        logger.debug('IN:%s', r)
                SystemLogicCommand.stdout_queue.put('<END>')
                logger.debug('END clct')
                #Logic.command_close()

            for tgt in [rdr, clct]:
                th = threading.Thread(target=tgt)
                th.setDaemon(True)
                th.start()