Sleep timer but still responsive?

JohnnyFive morganhein at gmail.com
Fri Jan 29 19:24:48 CET 2010


On Jan 29, 9:33 am, Andreas Tawn <andreas.t... at ubisoft.com> wrote:
> > On Jan 28, 4:55 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> > wrote:
> > > Please provide more details. What do you want your program to do
> > while
> > > sleeping? What kind of actions do you want a response to?
> > > Do you have a GUI? A curses-based interfase?
>
> > > --
> > > Gabriel Genellina
>
> > My app is purely console based. I just don't want the console to lock
> > up (on Windows using time.sleep(x) causes the console to become
> > unresponsive until the timer is done), and I want people to be able to
> > CTRL+C to stop the script if need be (which can't be done if it's
> > unresponsive!).
>
> > Thanks.
>
> How about this? Responds to ctrl+c, but still sleeps.
>
> import time
>
> def responsiveSleep(n):
>     while n > 0:
>         time.sleep(1)
>         n -= 1
>
> Cheers,
>
> Drea

Thanks for the ideas! Maybe it's just my computer, but using your
solution still causes the prompt to become unresponsive during the
sleeps.

I am using 2.6.4 btw. It's not a major deal though, I just thought
there had to be a way to do this fairly easily.



More information about the Python-list mailing list