@threaded is a collection of Python decorators for easy threading. They come in handy when you have a function that you want to run in a separate thread, but you don't want to (or don't need to) deal with threading objects.
Inherits daemon property from the current thread.
The resulting thread is a daemon thread.
The resulting thread is a non-daemon thread.
The thread's daemon property is opposite than that of the current thread.
Delays function call for a float number of seconds. Pass to the function call as
_delay=seconds
where seconds is a floating point number. This must be combined
with one of the decorators above to work.
import threaded
import time
# Replace with threaded.daemon and run again. Notice any changes?
@threaded.inherit
def print_odd_numbers(limit, interval):
number = 1
while number < limit:
print('\t', number)
number += 2
time.sleep(interval)
def print_even_numbers(limit, interval):
number = 0
while number < limit:
print(number)
number += 2
time.sleep(interval)
print('MAIN\t', '2ND THREAD')
print_even_numbers(30, 0.25) # will be run in MAIN thread
print_odd_numbers(30, 0.5, _delay=1.5) # will be run in 2ND thread