Reputation:
I have a python script A and a python script B.
Both of them are running independently. I want, as soon as script B finishes execution, it should send a message to script A, "B Done".
A simple message could have been sent by sockets et al. However, script A is doing some work of its own. How do I make A listen for B without halting the execution of A?
Any help is much appreciated!
EDIT:
B is entirely CPU bound - calculations. A is a mix of I/O bound and CPU-bound. The user is intervening at irregular intervals with inputs (keylogger like setup) where I/O is obviously the keystrokes, and CPU bound task is some calculations being performed on the entered key.
Upvotes: 0
Views: 147
Reputation: 7765
There are many solutions to this area of problem.
You might want to checkout ZMQ which makes it easy to create a messaging pattern between applications.
The message channel would run in its own thread, which might be a "green" thread to avoid unnecessary overhead if used together with gevent.
A few examples combining gevent and zmq: https://github.com/zeromq/pyzmq/tree/master/examples/gevent
A great guide for different messaging patterns: ZMQ Guide
Use these libraries to create a channel between A and B which continuously polls for new work and reports the results back.
Some other solutions exist where you have a broker in between A and B, but setting up the link between the nodes directly would probably be more suitable for an interactive-ish application like the one you are describing.
Upvotes: 1