python - How can I continuously check the hour within a while loop? -
this first post , first project in python. i'm trying control hardware sensor through number of conditions: if sensor senses movement, send e-mail , sleep elif time range not between work hours, sleep until 9am else sleep half second , wait sensor so far first condition , last condition work. is, if there no movement, repeat sleep(0.5) until sensor activates. issue: i'm having trouble middle portion time not between 9-5. if run code before 9 or after 5, sleeps until 9am arrives intended, if code running between 9-5 (waiting movement), middle condition never triggers. gets stuck on sleep(0.5). i'm not experienced have vague idea second process should keep track of time. suggestions? here code. def pir_init(): while true: m = datetime.datetime.now().time().minute #loop through current time h = datetime.datetime.now().time().hour if h < 9: print("sleeping......