Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

Python • Re: Change sleep duration of a loop without restarting it (use a variable from an imported script?)

$
0
0
Could I have it import the variable from another script that I could update without interrupting the running code?
Just check if a text file exists at the end of time.sleep().
If it does set SLEEPDUR = 43200
else set SLEEPDUR = 3600.

Code:

from pathlib import Pathmy_file = Path("/path/to/file")if my_file.is_file():SLEEPDUR = 43200else:SLEEPDUR = 3600
So to create the file just use touch from the command line
Then when you are ready just delete it.
I could do multiple "elif" lines with a variety of SLEEPDUR values. I could create the files (likely naming them the desired values) and move them in and out of the folder for them to be seen. The only issue I see is that if it is on a 6 hour cycle, then I would have to wait until that cycle is done for it to be changed to a different SLEEPDUR value.

Statistics: Posted by duckredbeard — Fri Jan 24, 2025 9:03 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles