Open KKimj opened 3 years ago
구현할 순서는 다음과 같다.
import multiprocessing
import os
import time
import signal
speed = 10
def input_handler():
# x = input('입력')
try:
while True:
x = input('입력')
print('결과', x)
time.sleep(1)
except KeyboardInterrupt:
return
def sonic_handler():
try:
while True:
x = [1,2,3]
print('sonic', x)
time.sleep(1)
except KeyboardInterrupt:
return
def motor_handler():
try:
while True:
global speed
speed+= 10
print('motor', speed)
time.sleep(1)
except KeyboardInterrupt:
return
def multiprocess():
procs = []
proc = multiprocessing.Process(target = sonic_handler, args=[])
procs.append(proc)
proc = multiprocessing.Process(target = motor_handler, args=[])
procs.append(proc)
try:
for proc in procs:
proc.start()
input_handler()
except KeyboardInterrupt:
for proc in procs:
# proc.join()
os.kill(proc.pid, signal.SIGTERM)
print('end..')
if __name__ == '__main__':
multiprocess()
input handling library : https://pypi.org/project/inputs/
multiprocessing으로 분기할 요소는 다음과 같다.