在OPCUA 中订阅某个结点值是否有变化,并做出相应处理。启动新线程去读取OPCUA结点值,出现以下错误:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/tonyyan/Documents/HamerOPCUA/Hamer_implementation/client.py", line 66, in show_new_values
code = self.PosObj.get_child(["{}:Code".format(self.idx)])
File "/Users/tonyyan/Documents/HamerOPCUA/venv/lib/python2.7/site-packages/opcua/common/node.py", line 471, in get_child
result = self.server.translate_browsepaths_to_nodeids([bpath])
File "/Users/tonyyan/Documents/HamerOPCUA/venv/lib/python2.7/site-packages/opcua/client/ua_client.py", line 427, in translate_browsepaths_to_nodeids
data = self._uasocket.send_request(request)
File "/Users/tonyyan/Documents/HamerOPCUA/venv/lib/python2.7/site-packages/opcua/client/ua_client.py", line 83, in send_request
data = future.result(self.timeout)
File "/Users/tonyyan/Documents/HamerOPCUA/venv/lib/python2.7/site-packages/concurrent/futures/_base.py", line 464, in result
raise TimeoutError()
TimeoutError
解决方法: 去除线程后面的join
t = Thread(target=self.show_new_values)
t.start()
t.join(5)
t = Thread(target=self.show_new_values) t.start() # t.join(5)
猜测原因:
并发死锁:
https://rednafi.github.io/digressions/python/2020/04/21/python-concurrent-futures.html