FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.32k stars 661 forks source link

Thread Error:OSError: [WinError 10038] 在一个非套接字上尝试了一个操作 #1449

Closed alexchan0412 closed 2 years ago

alexchan0412 commented 2 years ago

Good afternoon,I'm come form china I wrote the code below: `from opcua import Client import time from threading import Thread import queue work = queue.Queue(1000) client = Client("opc.tcp://127.0.0.1:49320") def task1(): # 定义任务1 try: while 1: client.connect() T = client.get_node('ns=2;s=test.mac.TA1').get_value() work.put(T) time.sleep(0.1) except Exception as e: print(e) finally: client.disconnect()

def task2(): while 1: time.sleep(0.5) print(work.get())

def main(): # 定义main函数 t1 = Thread(target=task1) # 定义线程t1,线程任务为调用task1函数,task1函数的参数是6 t2 = Thread(target=task2) # 定义线程t2,线程任务为调用task2函数,task2函数无参数 t1.start() # 开始运行t1线程

t1.join() # t1线程完成了才执行后续的动作

t2.start()  # 开始运行t2线程

if name == 'main': main() # 调用main函数`

Error Meessage: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\client.py", line 299, in disconnect self.close_secure_channel() File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\client.py", line 343, in close_secure_channel return self.uaclient.close_secure_channel() File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\ua_client.py", line 282, in close_secure_channel return self._uasocket.close_secure_channel() File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\ua_client.py", line 223, in close_secure_channel future = self._send_request(request, message_type=ua.MessageType.SecureClose) File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\ua_client.py", line 72, in _send_request self._socket.write(msg) File "C:\Users\chenh\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\common\utils.py", line 118, in write self.socket.sendall(data) OSError: [WinError 10038] 在一个非套接字上尝试了一个操作。

How can i fix it? Now in china,many engineer want use Python in electric design. But only some people use FreeOpcUA in learning video No one konws haw to use it in internet who can teach me??

AndreasHeine commented 2 years ago

your issue does not really look like a issue with this library rather like a issue in using threading module! the issue with most youtube videos online is that they just show hello world stuff which does not mirror industrial production usecases and the real world. if you really want to use OPC UA you need at least read Part 1 of the spec which shows the concepts of it.

swamper123 commented 2 years ago

Hey ho,

this repository is not maintained anymore.

Please switch to our other repository: https://github.com/FreeOpcUa/opcua-asyncio We have got some examples there, how to use the library.

We have a discussion board for questions as well for more questions.