need help about time.sleep, timer

Sinan Nalkaya erchamion.beren at
Mon Nov 21 09:35:20 CET 2005

Dennis Lee Bieber wrote:

>On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen <peter at>
>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 
>	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...
>	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():

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

More information about the Python-list mailing list