0

Consider my main script as a loop that is constantly broadcasting various events happening. For example:

FileChange: File at address XXX has changed.
FileDeleted: File at address XXX has been deleted.
ScreenSaver: Screen saver named YYY got activated.
...

What I intend to do is to have other apps that I would add now (and later on), listen to what main app is broadcasting and if it is related to it (say a script for handling FileChange events), they get the message and do their own processing.

What are my options for achieving this model of interprocess communication?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
wiki
  • 1,877
  • 2
  • 31
  • 47

1 Answers1

0

If you structure your application using threads you could use the python queue library for that https://docs.python.org/3/library/queue.html - it is a class supporting multiple producers and consumers. I often use that for structuring my applications for propagating events among different listeners.

If you want to separate different processes you could choose something from Recommended Python publish/subscribe/dispatch module?

In your case a unix domain socket could be a simple possibility without using difficult frameworks (you could even write shell programs for accessing that). Meanwhile it seems to work under Windows as well (AF_UNIX equivalent for Windows). Your service could publish events with a simple ASCII protocol like <EVENT>:<PATH> on the socket.