Nov-18-2020, 11:29 PM
Pages: 1 2
Nov-19-2020, 01:09 AM
What is an input timer? What do you want it to do, and what have you tried so far?
Nov-19-2020, 01:20 AM
ill post a link of something i had posted the problem is if the time runs out it does not reset the loop properly so i have tired other ways but they all have failed
https://python-forum.io/Thread-input-timer
https://python-forum.io/Thread-input-timer
Nov-19-2020, 02:26 AM
Need your code post, it is unclear what you are trying to do. For example, are you trying to wait for the user to make an entry, but do something if they dont within a specific time?
Nov-19-2020, 02:51 AM
@jefsummers the link to my code is right above your comment. the code is on a different post already made with more detail on what I'm trying to do I'm re asking it maybe i posted it at a bad time i got no replies on it.
Nov-19-2020, 04:48 AM
First, these don't seem to really be "wake words" if you have to process them. They're more like guard words as a check. But it looks to me like both the wake and the control are coming in the same input channel.
I can think of a couple of approaches.
One is write it multithreaded. Have one thread get the input (which can block), but then put the info into a queue for the other thread to read. The other thread can timeout if the queue doesn't give any information in the time.
A perhaps simpler way is to loop over input, but then just check a timer for when the input arrived. If it's been too long since the last input, only process it as a wake word. If the time has been short, process as control. The disadvantage is that you can't report that you're transitioning to "asleep", because you're blocking on the input.
I can think of a couple of approaches.
One is write it multithreaded. Have one thread get the input (which can block), but then put the info into a queue for the other thread to read. The other thread can timeout if the queue doesn't give any information in the time.
A perhaps simpler way is to loop over input, but then just check a timer for when the input arrived. If it's been too long since the last input, only process it as a wake word. If the time has been short, process as control. The disadvantage is that you can't report that you're transitioning to "asleep", because you're blocking on the input.
import time WAIT_TIME = 5 # max wait time in seconds WAKE_WORDS = ["Hello", "Mornin", "Howdy", "Hi"] last_input = 0 state = "asleep" while True: text = input() input_time = time.time() if input_time - last_input > WAIT_TIME: state = "asleep" last_input = input_time if state == "asleep": if text in WAKE_WORDS: print("Hello, what can I do for you?") state = "awake" else: print(" debug: wake word not found while asleep. ") elif state == "awake": print(f"I am processing {text} now")
Output:$ python3 timerloop.py
not wake word
debug: wake word not found while asleep.
Hi
Hello, what can I do for you?
dothis
I am processing dothis now
dothis # typed after waiting 5 seconds
debug: wake word not found while asleep.
Nov-19-2020, 10:03 PM
I think i get what you are saying about the multithreaded approach and I like it. im going to do some research on it. You have given me some stuff to thinking about and definitely a good starting point to expand on thank you.
Nov-19-2020, 10:08 PM
You might be trying to reinvent the wheel.
you can use the schedule module to set timed events, and it is just a matter of creating functions for it to run.
you can use the schedule module to set timed events, and it is just a matter of creating functions for it to run.
Nov-19-2020, 10:15 PM
(Nov-19-2020, 10:03 PM)Nickd12 Wrote: [ -> ]I think i get what you are saying about the multithreaded approach and I like it. im going to do some research on it. You have given me some stuff to thinking about and definitely a good starting point to expand on thank you.
This is an older page on it, but seems still relevant. As it explicitly uses a multithreaded approach, it might have some starting points. https://repolinux.wordpress.com/2012/10/...in-python/
Nov-23-2020, 09:50 PM
so ive been doing some research is the only way to do it with sys.stdin
Pages: 1 2