Ali baba
Ali baba

Reputation: 97

what is equivalent to sigusr1-2 signals in windows using python?

Please I need some help. I am struggling with sending a notifications between two python processes in windows.

I have looked in signals module but unfortunately user defined signals are not supported in windows.

Windows uses something else called messages, but I don't know how it works or how to use it in python. If someone has an idea or a starting point for sending messages between processes in python that would be appreciated.

Upvotes: 5

Views: 8163

Answers (3)

yoonghm
yoonghm

Reputation: 4645

There is no SIGUSR1 nor SIGUSR2 in Windows platform. You can confirm by doing this:

C:\>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda custom (64-bit) on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> dir(signal)
['CTRL_BREAK_EVENT', 'CTRL_C_EVENT', 'Handlers', 'NSIG', 'SIGABRT', 'SIGBREAK', 'SIGFPE', 'SIGILL', 'SIGINT', 'SIGSEGV', 'SIGTERM', 'SIG_DFL', 'SIG_IGN', 'Signals', '_IntEnum', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_enum_to_int', '_int_to_enum', '_signal', 'default_int_handler', 'getsignal', 'set_wakeup_fd', 'signal']

Here 1 is the official documentation from Windows.

Upvotes: 0

mdscruggs
mdscruggs

Reputation: 1212

It really depends on what you're looking for- whether you want control over messages, non-blocking messages, or the ability to capture external signals like you normally would with the signal module.

Since you want to send "notifications between two python processes" I recommend the multiprocessing.connection module's Client and Listener classes for a very easy message-oriented pair of connection objects:

http://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.connection

In Process A:

listener = Listener(('localhost', 9000)) # local TCP connections on port 9000
remote_conn = listener.accept()
listener.close()
print remote_conn.recv()
# prints 'a pickle-able object'
print remote_conn.recv()
# prints "['another', 'pickle-able', 'object']"

In Process B:

client = Client(('localhost', 9000))
client.send('a pickle-able object')
client.send(['another', 'pickle-able', 'object'])

The fact that these classes are built-in makes me happy- no installations required! Just be careful to follow the docs guidelines about security and un-pickling data.

Upvotes: 2

Stefano Sanfilippo
Stefano Sanfilippo

Reputation: 33116

Try zeromq for interprocess communication via sockets.

Upvotes: -1

Related Questions