Files
pythonprimes/addit.py
ducoterra 0a652e8f4c init
2018-08-14 00:20:31 -04:00

66 lines
1.1 KiB
Python

from time import time
from threading import Thread
from multiprocessing import Process
def timeit(func):
"""
prints the time a function takes to run
:param func:
:return:
"""
def wrapper(*args):
t1 = time()
func(*args)
t2 = time()
print("Time to run: " + str(t2 - t1))
return wrapper
def printit(func):
"""
prints a string before and after the function
:param func:
:return: wrapper
"""
def wrapper(*args):
print("Starting " + str(args))
func(*args)
print(str(args) + " done!")
return wrapper
def threadit(func):
"""
starts a function in its own thread
:param func: the function
:return: wrapper
"""
def wrapper(*args):
t = Thread(target=func, args=args)
t.start()
return wrapper
def processit(func):
"""
starts a function in its own process
:param func: the function
:return: wrapper
"""
def wrapper(*args):
p = Process(target=func, args=args)
p.start()
return p
return wrapper
@processit
def test():
while True:
pass