So this is my scenario. I have a python script that runs in an infinite while loop which takes in user input.
But I now want another function to to do stuff every n seconds while the main loop, which is blocking (waiting for python's input() function), is still running. I have looked into asyncio and scheduling but they don't seem to work with blocking function calls, or am I mistaking?
I have looked into multiprocessing but couldn't wrap my head around how exactly I would be supposed to do that yet.
EDIT:
if __name__ == "__main__":
def survivor():
count = 5
while count:
print("alive")
time.sleep(8)
count -= 1
print("done")
test = JobChainClient()
cli = threading.Thread(name="cli", target=test.getShell())
network = threading.Thread(name="network", target=survivor())
cli.start()
network.start()
print("Done")
This code gets my CLI which is a infinite while loop and my network daemon. When I run this it obviously works but the problem is this:
(JobChain) > exit
Closing JobChain client now!
alive
alive
alive
My loop breaks after the exit command and only than does the other thread start, I probably just missed something here, please correct me.