简体   繁体   English

如何在python中暂停并从一个进程向另一个进程发送信号

[英]How to pause and send signal from one process to other in python

New to python so this might sound like a basic question. python的新手,所以这听起来像是一个基本问题。 I have a new process spawn off the main process to do something in parallel with the main process. 我从主流程中产生了一个新流程,以与主流程并行进行某些操作。 I cannot use threads in this specific case cause of some underlining APIs threading issues . 在这种特定情况下,由于某些底层API线程问题,我无法使用线程 I am trying to achieve some synchronization among both the processes. 我正在尝试在两个过程之间实现某种同步。 I read about signals but I couldn't find a proper example which aligns with my case. 我读了一些信号,但找不到适合我情况的适当示例。 Some example code: 一些示例代码:

import multiprocessing
import signal
def process_one(self):
    # Do something
    second_process = Process(target=self.process_two)
    second_process.start()
    # Do something and send signal to process_two to unpause
    # Do other things
    second_process.join()

def process_two(self):
    # Do something
    # Now I want to pause this process till I receive a signal from
    # process_one
    signal.pause()
    # continue to do other things

As I have mentioned in the comments, I am trying to figure out a way to achieve this. 正如我在评论中提到的那样,我正在尝试找出一种方法来实现这一目标。 Most of the examples I saw were for forks . 我看到的大多数例子都是forks Pointers? 指针?

Solved it using Event() 使用Event()解决了它

The example posted there was exactly what I wanted. 发布的示例正是我想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM