Answers for "python terminate program after specific time"

0

python terminate program after specific time

import multiprocessing
import time

# Your foo function
def foo(n):
    for i in range(10000 * n):
        print "Tick"
        time.sleep(1)

if __name__ == '__main__':
    # Start foo as a process
    p = multiprocessing.Process(target=foo, name="Foo", args=(10,))
    p.start()

    # Wait 10 seconds for foo
    time.sleep(10)

    # Terminate foo
    p.terminate()

    # Cleanup
    p.join()
Posted by: Guest on November-08-2020

Code answers related to "python terminate program after specific time"

Python Answers by Framework

Browse Popular Code Answers by Language