代码之家  ›  专栏  ›  技术社区  ›  AutoTester213

Python多线程-Rawlink错误连接。等等()

  •  0
  • AutoTester213  · 技术社区  · 6 年前

    我正在尝试用python多线程处理一个单R连接,我得到了一个连接 Rawlink 错误连接工作,我需要等待1秒,以接收来自客户端的消息,我还使用了一个障碍执行线程“同步”。

    这是我的密码

    with Session() as session:
        global connection
        connection = Connection("http://sampleSINGALRURL/signalr", session)
        presenceservice = connection.register_hub('ClientRegistration')
        presenceservice1 = connection.register_hub('PresenceClientHub')
        connection.start()
        presenceservice.server.invoke('IdentifyClient', devideIdentity, softwareVersion, IpAddress,
                                      machineName, DeviceType, patientAdmissionGuid, patientID, pairingId)
        presenceservice1.client.on('StaffPresenceNotified', self.get_data1)
        connection.wait(1)
    

    然后我的线程功能

    def get_clients(self):
        global barrier
        self.connect_to_database1()
        barrier.wait()
        self.get_message_from_client1()
        self.print_data1()
    
    def send_messages(self):
        global MessageNumber
        global machineName
        global staffName
        global request
        machineName = final_result[MessageNumber][0]
    
        staffName = staff_results[MessageNumber][0]
        MessageNumber += 1
        barrier.wait()
        request = requests.post(
            "http://sampleurl/api/sample")
        return request
    def print_response(self):
        global request
        timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
        logging.info("Message sent at "  + "Time : " + timestamp + " " + machineName)
    
    
    def Spin_Clients(self, NumMessages):
        for i in range(10):
            self.client_list.append(Thread(target=self.send_messages))
            self.client_list[i].start()
            self.print_response()
        sleep(2)
        for i in range(10):
            self.Message_List.append(Thread(target=self.get_clients))
            self.Message_List[i].start()
        for thread in self.client_list:
            thread.join()
        for thread in self.Message_List:
            thread.join()
    

    错误日志

    All threads have finished    
    11:41:37.243    
    Exception in thread Thread-13: Traceback (most recent call last):   File "c:\users\appdata\local\programs\python\python37\lib\threading.py", line 917, in _bootstrap_inner
            self.run()   
    File "c:\users\appdata\local\programs\python\python37\lib\threading.py", line 865, in run
            self._target(*self._args, **self._kwargs)   
    File "C:\Data\LoadTest.py", line 103, in get_clients
            self.get_message_from_client1()   
    File "C:\Data\LoadTest.py", line 89, in get_message_from_client1
            connection.wait(1)  
    File "c:\users\appdata\local\programs\python\python37\lib\site-packages\signalr\_connection.py", line 60, in wait
                gevent.joinall([self.__greenlet], timeout)   
     File "src\gevent\greenlet.py", line 849, in gevent._greenlet.joinall  
     File "src\gevent\greenlet.py", line 859, in gevent._greenlet.joinall   
     File "src\gevent\_hub_primitives.py", line 198, in gevent.__hub_primitives.wait_on_objects   File "src\gevent\_hub_primitives.py", line 235, in gevent.__hub_primitives.wait_on_objects   
     File "src\gevent\_hub_primitives.py", line 125, in gevent.__hub_primitives._WaitIterator.__iter__ AttributeError: 'NoneType' object has no attribute 'rawlink'
    

    你知道吗?

    0 回复  |  直到 6 年前