how to stop a program after 1 second in python

Solutions on MaxInterview for how to stop a program after 1 second in python by the best coders in the world

showing results for - "how to stop a program after 1 second in python"
Tony
09 Jun 2020
1import multiprocessing
2import time
3
4# Your foo function
5def foo(n):
6    for i in range(10000 * n):
7        print "Tick"
8        time.sleep(1)
9
10if __name__ == '__main__':
11    # Start foo as a process
12    p = multiprocessing.Process(target=foo, name="Foo", args=(10,))
13    p.start()
14
15    # Wait 10 seconds for foo
16    time.sleep(10)
17
18    # Terminate foo
19    p.terminate()
20
21    # Cleanup
22    p.join()
23