Mobileread
IPC between plugin and interface
#1  Sytten 04-11-2020, 05:54 PM
Hi!

I need to do a Google login for my plugin. Reading the documentation, I see that I need to launch that in a separate process. However I don't have a way to communicate back information to my plugin (mainly access and refresh tokens). I took a look at how other core plugins do it and it seems to use the IPC utils, but only some predefined messages are handled and it is currently not possible to register an handle for new message types.
Is there any way I could make that work?

Thanks!
Reply 

#2  kovidgoyal 04-12-2020, 01:21 AM
A plugin can run arbitrary code (the only exception being it cant use Qt WebEngine), you can do IPC however you like. Use the python multiprocessing classes or a simple socket or stdin/stdout, or a file in the filesystem, whatever you are comfortable with.
Reply 

#3  Sytten 04-12-2020, 06:48 PM
Ha yes that makes sense, thanks!
Other small question, is the networkauth module included in the main process? I would like to use QOAuth2AuthorizationCodeFlow if possible.
Reply 

#4  kovidgoyal 04-12-2020, 10:37 PM
No, I dont think so. You can see th elist of Qt modules included by looking at sources.json in the calibre source tree.
Reply 

#5  Sytten 05-10-2020, 06:17 PM
I tried using the multiprocessing Queue class, but it doesn't seem possible to pass it through the IPC. From what I understand what the IPC module does:
Job -> Worker -> ConnectedWorker -> Sends the kwargs to the worker via pipe
But the only way to send a Queue is when you spawn the child process, otherwise you get an error: Queue objects should only be shared between processes through inheritance.
I will try to use a Dispatcher with a Job result to see if that works.
Reply 

#6  kovidgoyal 05-10-2020, 11:56 PM
I would strongly recommend against sending anything other than primitive data types such as strings/numbers and list/dicts of those between processes. If you want to do cross process synchronization use a lockfile or platform specific mutexes. Sending a queue requires shared memory which may or may not be available depending on platform.
Reply 

Today's Posts | Search this Thread | Login | Register