Created
March 2, 2020 05:01
-
-
Save HwDhyeon/aa537f9d0a5f6ed2113ca72a2bd93b6c to your computer and use it in GitHub Desktop.
Python multiprocessing 모듈을 이용해 타임아웃 구현하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
import time | |
import sys | |
TIMEOUT = 5 | |
def tenSecond(): | |
for i in range(10): | |
sys.stdout.write('\r{} sec'.format(i + 1)) | |
time.sleep(1) | |
print('\nDone!!') | |
def do(a): | |
tenSecond() | |
if __name__ == "__main__": | |
print('This program has a 5 second timeout.') | |
a = 'arg1' | |
actionProcess = Process(target=do, args=(a, )) | |
actionProcess.start() | |
actionProcess.join(timeout=TIMEOUT) | |
actionProcess.terminate() | |
print('\nProcess is End') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment