I got the following code which has the goal of running multiple while loops threaded simultaneously.
This worked for me and achieved the expected results but has the "odd" behavior of fully utilizing exactly one logical core of the cpu.
The looped functions doesn't do much other than waiting with the sleep function.
from time import sleep
sleep(60)
I can't call the functions periodically. Does someone here know why that is?
def changes(function, name):
if function == 0:
pass
elif function == 1:
print("something changed in " + str(name))
else:
print("something went wrong in " + str(name))
def loop_function0():
while True:
changes(function0(argument), "function0")
def loop_function1():
while True:
changes(function1(argument), "function1")
class thread0(Thread):
def __init__(self):
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
loop_function0()
class thread1(Thread):
def __init__(self):
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
loop_function1()
thread0()
thread1()
while True:
pass