什么等于在Windows中使用python的sigusr1-2信号? [英] what is equivalent to sigusr1-2 signals in windows using python?

查看:160
本文介绍了什么等于在Windows中使用python的sigusr1-2信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我需要一些帮助.我正在努力在Windows中的两个python进程之间发送通知.

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

我已经看过信号模块,但是不幸的是,Windows不支持用户定义的信号.

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

Windows使用其他称为消息的东西,但是我不知道它是如何工作的,或者如何在python中使用它.如果有人对在python中的进程之间发送消息有想法或起点,将不胜感激.

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.

推荐答案

这实际上取决于您要查找的内容-是要控制消息,非阻塞消息,还是像通常一样捕获外部信号的能力将使用signal模块.

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.

由于要发送两个python进程之间的通知",因此我推荐multiprocessing.connection模块的Client和Listener类用于一对非常简单的面向消息的连接对象:

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

在过程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']"

在过程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.

这篇关于什么等于在Windows中使用python的sigusr1-2信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆