Skip to content

Instantly share code, notes, and snippets.

@HwDhyeon
Created March 2, 2020 05:01
Show Gist options
  • Save HwDhyeon/aa537f9d0a5f6ed2113ca72a2bd93b6c to your computer and use it in GitHub Desktop.
Save HwDhyeon/aa537f9d0a5f6ed2113ca72a2bd93b6c to your computer and use it in GitHub Desktop.
Python multiprocessing 모듈을 이용해 타임아웃 구현하기
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