Trying to reach the next part of my code in python

Viewed 33

i am trying to make a loop that screenshots every 30 seconds and saves it in a folder

This is what I have now:

while True: 
       time.sleep(30)
       takeScreenshoot(path)
       print('ScreenShoot Taken')

however now because of this the next part of my code is unreacheable but it does take a screenshot every 30 seconds how can i make it so that icontinues to the next part of my script

1 Answers
from threading import Thread
import time

def f(x):
   while True:
    time.sleep(2.1)
    print(f'ScreenShoot Taken: {x}')


def g(x):
   for i in range(5):
    time.sleep(2.2)
    print(f'Ho Ho Ho: {x}')


f = Thread(target=f, args=["bla"])
f.daemon = True
f.start()
g("bla")

In this example both functions work at the same time. You can of course replace g() with your code. If you do not set the thread to daemon, the program will not quit, becuase the thread function f() runs infinitely. If it is set to daemon, the thread will exit the moment the main code exits.

Related