-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: OpcDaClient problems with Multithreading #45
Comments
Multithreading is supported via the gateway. Just make sure you create the
proxy in the thread where you use it. Or pass the ownership (see pyro docs)
What happens in your case when you create the connection in the same thread
as you use it?
|
Thanks for the speedy response!
This is good, it focuses us on the
Thanks for pointing this out, yeah I realize that, and it's at the core of this issue. For some reason, OpenOPC v1 didn't have this issue, perhaps something changed related to security between Pyro4 and Pyro5. Unfortunately, due to the framework I'm using, I can't control which thread creates the
Okay, reading here: https://pyro5.readthedocs.io/en/latest/clientcode.html?highlight=thread#proxy-sharing-between-threads
I work in the biotech space where we have lots of devices being concurrently controlled from one Python process. We make heavy use of multithreading. The fact that That being said, based on >>> opc_client._pyroClaimOwnership()
Traceback (most recent call last):
File "C:\path\to\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-493afd7395b1>", line 1, in <module>
self._opc_client._pyroClaimOwnership()
AttributeError: 'OpcDaClient' object has no attribute '_pyroClaimOwnership'
>>> opc_client._opc._pyroClaimOwnership()
Traceback (most recent call last):
File "C:\path\to\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-2b72a8ebc0c5>", line 1, in <module>
self._opc_client._opc._pyroClaimOwnership()
AttributeError: 'OpcCom' object has no attribute '_pyroClaimOwnership' I am getting attribute errors on both |
@eliabieri a nit on the label applied is I think this a bug, not a question. I don't think it's possible to use opc = OpcDaClient(open_opc_config=open_opc_config)
thread = Thread(
target=opc.connect, kwargs={"opc_server": MATRIKON_SIMULATION_SERVER}
)
thread.start()
thread.join()
result = opc.read("Random.Boolean") If you can help me figure this out, I can become an adopter of OpenOPC 2. |
You can use it in multithreading. We do so with celery for example.
|
Hi @renzop thank you for responding!
from openopc2.config import OpenOpcConfig
from openopc2.da_client import OpcDaClient
MATRIKON_SIMULATION_SERVER = "Matrikon.OPC.Simulation"
open_opc_config = OpenOpcConfig()
open_opc_config.OPC_SERVER = MATRIKON_SIMULATION_SERVER
opc = OpcDaClient(open_opc_config=open_opc_config)
opc._pyroClaimOwnership() This leads to an Traceback (most recent call last):
File "C:\path\to\file.py", line 10, in <module>
opc._pyroClaimOwnership()
AttributeError: 'OpcDaClient' object has no attribute '_pyroClaimOwnership' Can you link me to your celery worker code? I don't know how your celery worker runs, given this |
I have discovered that if you try to connect the
OpcDaClient
on a thread, it throws anException
. Please see the below code snippet (done with MatrikonOPC Simulation Server):If you use the main thread the whole time, this works.
If you call
OpcDaClient.connect
on a thread, you get thisException
whenOpcCom.connect
callsself.opc_client.Connect
:Notable, OpenOPC (not OpenOPC 2) doesn't have this error:
This is a bummer for me, because I use a software framework where all device connections are all made asynchronously (on a thread). I would like to use OpenOPC2, but this is an issue.
The text was updated successfully, but these errors were encountered: