Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

communication between python programs

Tags:

python

process

I have a python program that is running as a daemon on Linux.

How to send this daemon a signal from another python program?

like image 608
Pydev UA Avatar asked Jul 29 '10 14:07

Pydev UA


4 Answers

Use os.kill to send signals. The signals are defined in the signal module. You'll just need to get the pid of the daemon in some way.

One more thing - you can use the signal module to register signal handlers as well.

like image 107
Jeremy Brown Avatar answered Nov 06 '22 21:11

Jeremy Brown


If you need something more sophisticated than simple signals, consider using an RPC library like PYRO. The advantage of this is that you can use it even if you have to move your processes to separate servers.

Or, if you mainly target Linux systems, then look at using DBUS instead. There is a python library and it is now even supported on Windows.

like image 22
Michael Dillon Avatar answered Nov 06 '22 21:11

Michael Dillon


Have you tried reading through the docs on interprocess communication in Python? Here is a link:

http://docs.python.org/library/ipc.html

like image 32
wshato Avatar answered Nov 06 '22 20:11

wshato


  • The daemon could have an open (network) socket, where it accepts commands.
  • It could monitor changes in a file.

Any other kind of signalling is possible, but these would probably be the most common.

like image 1
relet Avatar answered Nov 06 '22 19:11

relet