nivm200
Posts: 23
Joined: Fri Oct 09, 2015 9:13 am

time.sleep() stops code

Sat Mar 05, 2016 6:42 pm

I want to run a loop with a delay every time the code in it is called, but whenever I use time.sleep() I can only run one loop and I need more than 1 loop to run at certain time... how can I associate the the time for the loop only and not the rest of the code?

gordon77
Posts: 5074
Joined: Sun Aug 05, 2012 3:12 pm

Re: time.sleep() stops code

Sat Mar 05, 2016 6:59 pm

Post you code on here then we can see if we can help.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: time.sleep() stops code

Sat Mar 05, 2016 7:00 pm

For doing that, you should use a timer or threads. ;)

Laurens

nivm200
Posts: 23
Joined: Fri Oct 09, 2015 9:13 am

Re: time.sleep() stops code

Sun Mar 06, 2016 8:01 am

any example code for threads/timers? I will add me code once il get home.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: time.sleep() stops code

Sun Mar 06, 2016 8:23 am

Here are some example scripts using threads. :)
You need to make a function for every separate loop you want, and start it as a thread.

Laurens

nivm200
Posts: 23
Joined: Fri Oct 09, 2015 9:13 am

Re: time.sleep() stops code

Sun Mar 06, 2016 3:25 pm

thank you!

SSL
Posts: 2
Joined: Sun Mar 06, 2016 8:02 pm

Re: time.sleep() stops code

Sun Mar 06, 2016 8:21 pm

Even though this shouldn't be a problem, that I can see, try putting your variables into the loop if they're not already. I had a simular situation where the loop would only run once then stop, but if I put the variables I used in the loop it worked. If not, then I'm out of idea's. Good luck, though!

Return to “Beginners”