need help about time.sleep, timer
Sinan Nalkaya
erchamion.beren at gmail.com
Mon Nov 21 03:35:20 EST 2005
Dennis Lee Bieber wrote:
>On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen <peter at engcorp.com>
>declaimed the following in comp.lang.python:
>
>
>
>>It's quite unclear whether the last part, above, is one of your
>>*requirements*, or a description of a problem you are having with your
>>current approach. Do you *want* it to wait forever if you don't enter
>>anthing?
>>
>>
>>
> As I understand it, he (?) wants to accumulate characters to be
>passed to a certain function -- but the function is not to be invoked
>until after a time period has expired; the time period resetting on each
>character entered.
>
> Something I'd do with threads, queues, and sleep...
>
>PSEUDOCODE
>
>thread1:
> while not Shutdown:
> ch = getChar()
> q.put(ch)
>
>
>thread2: #or main
> while not Shutdown:
> chars = []
> while True:
> sleep(max_interval)
> if q.empty(): break #no input since start of sleep
> while not q.empty(): #collect all input from sleep
> chars.append(q.get())
> inp = "".join(chars)
> function(inp)
>
>
>
>
>
i appreciate your comments and ideas. Dennis told exactly what i tried
to say :), code seems to be fine but during sleep action i think the
above code does not execute
if q.empty(): break #no input since start of sleep
while not q.empty():
chars.append(q.get())
i need something, while sleeping, executes the function that waits for
input from keyboard.
i imagined something like that, i have a queu, it both stores the keys
that pressed and pressing times of these keys, then i`ll proccess these
times. here is scenario
input : 5
after 10 seconds later input 5 is being proccessed
return back to main function
input : 1
after 5 seconds , other input 5
after 5 more seconds , 15 is being proccessed
Thanks.
More information about the Python-list
mailing list