Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to stop a program after 1 second in python

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()
Comment

PREVIOUS NEXT
Code Example
Python :: tweepy aut code 
Python :: map example in python 
Python :: how to check dimension of array in python 
Python :: relative import in python 
Python :: planets list 
Python :: how to get user id django 
Python :: python if string contains substring 
Python :: drop row with condition dataframe 
Python :: python csv writer row by row 
Python :: generate random integers python 
Python :: Sum items in a list with ints and strings in python 
Python :: how to create dictionary in python from csv 
Python :: python pip Failed to build cryptography 
Python :: Using mapping in Converting categorical feature in to numerical features 
Python :: how to raise the exception in __exit__ python 
Python :: how to enter a int in python 
Python :: python json random number generator 
Python :: get dict values in list python 
Python :: np.mean 
Python :: python script that executes at time 
Python :: How to Crack PDF Files in Python - Python Cod 
Python :: change a cell in pandas dataframe 
Python :: tkinter label auto text wrap 
Python :: python string trim 
Python :: how to open a dataset in netcdf4 
Python :: python read excel 
Python :: custom attribute selenium 
Python :: python private method 
Python :: python generate pdf from template 
Python :: find max length of list of list python 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =