0

I am new to python coding (using pyscripter with the latest version of python (3.5)). I am wondering how to run 2 loops or scripts at the same time. IM using the graphics.py module and the time module. I need to open a window, create a countdown, and do a bunch of other stuff at the same time, but the problem is when i try t create a countdown using "time.sleep", it pauses the rest of the program. How would i go about creating a timer/countdown without pausing the rest of my script? Also it needs to be able to draw on the same window. Thank you very much.

Ryan K
  • 1
  • 1
  • 1
    You might want to look into the pygame module: http://www.pygame.org/wiki/GettingStarted . It's not just for games - it's a generic event loop. – J_H Sep 25 '17 at 00:59
  • Welcome on stackoverflow.com. Please always try to provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that shows where you got stuck. – wp78de Sep 25 '17 at 01:08

1 Answers1

1

You can create a (worker) thread to do some extra work without blocking the rest of your code.

Here is some basic code (below) to get you started and a how-to.

from threading import Thread
from time import sleep

def threaded_function(arg):
    for i in range(arg):
        print("running")
        sleep(1)   

if __name__ == "__main__":
    thread = Thread(target = threaded_function, args = (10, ))
    thread.start()
    thread.join()
    print("thread finished...exiting")
wp78de
  • 18,207
  • 7
  • 43
  • 71