Page 1 of 1

How to do inter-thread communication

PostPosted: Mon Oct 07, 2019 4:19 pm
by LRN
Let's say that i need to do something time-consuming. The normal way to go about it is to create a thread and make it do the work, then report back with the result.

Creating a thread is not difficult. The real question is how to communicate the result *back* from the worker thread to the main thread of my office extension. Extensions, AFAIK, do not run an event loop, so there might not even *be* a "main thread" of an extension at a given moment, just the office doing its thing. I thought that maybe i could register an XJobExecutor and then use the XAsyncJob to queue a job from the worker thread to be executed in the main thread - but it's difficult to find examples of something like this, and the SDK is almost completely silent on the subject of thread-safety.

This is compounded by the fact that i'm using Python (so i will probably need to use *processes* instead of threads (thank you, GIL!), which adds a whole new set of problems with regard to communication), and Python examples are almost non-existent (SDK has 1 (/one/) Python component example).

Re: How to do inter-thread communication

PostPosted: Mon Oct 07, 2019 5:17 pm
by sasa
Hi,

you can try solution in this thread, tested in dialogs and sidebar extension:
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=89503

Best

Re: How to do inter-thread communication

PostPosted: Thu Dec 19, 2019 5:38 pm
by psilocybe
Hi LRN,

Take a look at my http server https://github.com/prrvchr/OAuth2OOo/blob/master/OAuth2OOo/pythonpath/oauth2/wizardserver.py
It does two things.
- Waiting for a response from the OAuth2 consent screen ...
- Response with the appropriate redirect link.