I have a Process, which does not repeat (Selenium Webdriver), which can run up to 100 minutes and more. My problem is that I cant figure out a way to pause in the middle of the process.
I've been trying to resolve it with Events, but so far I just found solutions, which would stop the process after an iteration, I've been thinking that it would theoretically be possible to put a query after every line of code, which asks if event is set to continue processing, but that will be very hard, because I have about thousand lines of code in that function.
In this example I have also been trying to pause the main Process over a Event which is called from another process, which starts when the user gives an Input(e.g. Enter), but the processes are not connected and therefor the evet_func is still running further.
import time
import multiprocessing
def event_func(num):
print('\t%r has started' % multiprocessing.current_process())
for i in range(1000):
time.sleep(0.1)
print(i)
print('\t%r has finished' % multiprocessing.current_process())
def event_wait(event):
print("Event Wait called")
event.wait()
print("Event wait finished")
if __name__ == "__main__":
event = multiprocessing.Event()
m = multiprocessing.Process(target=event_func, args=(1,), daemon=True)
m.start()
x = input("Waiting for input: ")
p = multiprocessing.Process(target=event_wait, args=(event,))
p.start()
print ('main is sleeping')
time.sleep(2)
print ('main is setting event')
event.set()
m.join()
My expected result is that the process is pausable in the middle of the function and not after an iteration.