Python Forum
Pressure monitor for keg fridge
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pressure monitor for keg fridge
#2
One thing that I would do is create a timer event, rather than poll time.
This will free up the processor so other things can be done (if needed) while waiting for an event.

Try running this snippet:

example using threaded timer:
import time, threading


def threaded_timer(delay=1):
    print(f"In timer loop: {time.ctime()}")
    threading.Timer(delay, threaded_timer).start()

# wake up after 6 seconds (can use decimal here for times less than 1 sec)
threaded_timer(delay=4)

print('Do something while waiting for timer')
time.sleep(1)
print('Do something else while waiting for timer')
Notice that timer runs independently from other code.
Output:
In timer loop: Wed Dec 2 06:42:13 2020 Do something while waiting for timer Do something else while waiting for timer In timer loop: Wed Dec 2 06:42:17 2020 In timer loop: Wed Dec 2 06:42:18 2020 In timer loop: Wed Dec 2 06:42:19 2020 In timer loop: Wed Dec 2 06:42:20 2020 In timer loop: Wed Dec 2 06:42:21 2020 ...
j.crater likes this post
Reply


Messages In This Thread
Pressure monitor for keg fridge - by duckredbeard - Dec-02-2020, 05:03 AM
RE: Pressure monitor for keg fridge - by Larz60+ - Dec-02-2020, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Better Way to Monitor Time Request. bill_z 2 2,185 Oct-17-2020, 04:36 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020