from time import sleep
def o1():
while True:
print("1 : )")
sleep(1)
def o2():
while True:
print("2 : )")
sleep(1)
if __name__=="__main__":
import multiprocessing
p1 = multiprocessing.Process(target=o1)
p2 = multiprocessing.Process(target=o2)
p1.start()
p2.start()
def close():
print("close o1")
p1.join() #the process does not end as a result
def start():
print("start o1")
try:
p1.start()
except AssertionError:
print("Nothing")
import keyboard
keyboard.add_hotkey('q', close)
keyboard.add_hotkey('e', start) #after q, nothing happens trying to press "e"
I need to close the process and reopen it by hotkey. (I did two processes in the code, as this fully reflects the program in which I need this function)
I'm sorry for my english : )