Exemple #1
0
 def engine_start(self, task_id):
     sys.stdout.write(
         '%s  |*|MetasearchingEngine receive task_id|*|: %s\n' %
         (time.ctime(), task_id))
     try:
         engine = Metasearching_start(task_id, self.stdout, self.stderr,
                                      self.mysql_host, self.mysql_user,
                                      self.mysql_password, self.mysql_db,
                                      self.mongo_db, self.mongo_host,
                                      self.mongo_port, self.mongo_user,
                                      self.mongo_password,
                                      self.message_other_engine)
         engine.start()
     except Exception, e:
         sys.stderr.write(
             '%s  %s  task_id: %s: \n' %
             (time.ctime(), OtherError(e, 'engine_start'), task_id))
         traceback.print_exc()
Exemple #2
0
 def engine_start(self, task_id):
     sys.stdout.write(
         '%s  |*|receive task_id|*|: %s\n' % (time.ctime(), task_id))
     try:
         engine = FiltrateStart(task_id, self.mysql_host, self.mysql_db,
                                self.mysql_user, self.mysql_password,
                                self.mongo_db, self.mongo_host, self.mongo_port,
                                self.mongo_user, self.mongo_password, self.message_other_engine,
                                self.write_process_pid, self.remove_process_pid)
         engine.start()
     except Exception, e:
         sys.stderr.write('%s  %s  task_id: %s: \n' %
                          (time.ctime(), OtherError(e, 'engine_start'), task_id))
         traceback.print_exc()
         task_start_time = self.mysql_handle.get_task_last_time(task_id)
         if task_start_time is not False:
             self.mysql_handle.update_engine_state(
                 task_id, task_start_time, 'filtrate', 0)
         os._exit(0)
Exemple #3
0
        sys.stdout.write('%s: monitor port %s\n' %
                         (time.ctime(), self.server_port))
        sys.stdout.write(
            '————————————————————————————————————————————————————\n')
        sys.stderr.write(
            '————————————————————————————————————————————————————\n')
        while True:
            conn, addr = sock.accept()
            sys.stdout.write('%s  request from : %s: ' % (time.ctime(), addr))
            try:
                response_thread = threading.Thread(target=self.response_server,
                                                   args=(conn, ))  # 创建线程
            except Exception, e:
                sys.stderr.write(
                    '%s\n' %
                    OtherError(e, 'ServerBase run_server response message'))
            response_thread.start()  # 执行线程
        sock.close()

    def response_server(self, conn):
        '''
        响应当前服务接收到的请求,在子线程中完成,完成并行响应
        '''
        try:
            message = conn.recv(self.MESSAGE_SIZE)
            if message[0] is 'q':  # 用来解析客户端发来的请求,请求开始任务格式为qr+任务ID
                # conn.settimeout(5) #服务端等待客户端三秒
                sys.stdout.write('client message : %s \n' % (message, ))
                task_id = int(message[2:])
                if len(message) == 2:
                    conn.send('failed')