Skip to content

Make Sync Client and Server reusable#1503

Draft
miki5799 wants to merge 6 commits into
FreeOpcUa:masterfrom
miki5799:sync-reusable-client-1364
Draft

Make Sync Client and Server reusable#1503
miki5799 wants to merge 6 commits into
FreeOpcUa:masterfrom
miki5799:sync-reusable-client-1364

Conversation

@miki5799

Copy link
Copy Markdown

As the issue #1364 suggests, OpcUa Client (and Server) are not reusable, since disconnecting the client or stopping the server, stops the Sync Wrapper's ThreadLoop respectively and therefore lead to ThreadLoopNotRunnning exceptions on any call that depends on the ThreadLoop.

As in the discussion of #1364 the Sync Wrapper should start the ThreadLoop on connection (or server.start) if ThreadLoop is not alive anymore.
This proposed behaviour has been implemented in this PR.

Reopen ThreadLoop if  stopped previously analogous to init
Fixes FreeOpcUa#1364
Comment thread asyncua/sync.py
self.tloop = ThreadLoop()
self.tloop.start()
self.close_tloop = True
self.tloop.post(self.aio_obj.connect())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot have the same code several places. At least put that code in a method.
also if you want to delay threadloop initializatin, you might need to do it at several places not only here... there is a connect_sessionless method for example and maybe others...

Comment thread asyncua/sync.py
self.tloop = ThreadLoop()
self.tloop.start()
self.close_tloop = True
self.tloop.post(self.aio_obj.start())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrg same code again... Making that class re-usable might not be a good idea. there is probably a reason, threading.Thread is not reusable...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your time and effort, but could you clarify further, since I'm not quite sure in what way initializing a new Thread or ThreadLoop could pose a problem in this context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was simply refering to the fact the threading.Thread in the python standard library does not allow re-use. We copied their API when creating that class. We can make that class reusable, but I see your code over is not really clean, so maybe it is hard to solve that issue in a safe way...

@miki5799
miki5799 force-pushed the sync-reusable-client-1364 branch from 43f83d0 to 8dab330 Compare December 12, 2023 17:20
@miki5799
miki5799 marked this pull request as draft December 18, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants