Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

New to python so this might sound like a basic question. 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. 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. Pointers?

like image 274
noMAD Avatar asked Sep 10 '25 16:09

noMAD


1 Answers

Solved it using Event()

The example posted there was exactly what I wanted.

like image 143
noMAD Avatar answered Sep 13 '25 07:09

noMAD