Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22640
| References | <7619907723400632495@unknownmsgid> <CALwzidk_aLbsoaV4me87SzgzVuGgm1gX5qhgRDEYpCLvP1E_Aw@mail.gmail.com> <-5854393752682031995@unknownmsgid> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2012-04-03 15:48 -0600 |
| Subject | Re: Run once while loop |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1301.1333489744.3037.python-list@python.org> (permalink) |
On Tue, Apr 3, 2012 at 3:00 PM, Anatoli Hristov <tolidtm@gmail.com> wrote: > On 03 Apr 2012, at 22:45, Ian Kelly <ian.g.kelly@gmail.com> wrote: > >> On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov <tolidtm@gmail.com> wrote: >>> Hi, >>> >>> I'm trying to do a while loop with condition of time if time is >>> 12:00:00 print text, but for this one second the text is printed at >>> least 50 times, how can I print only once? >> >> Set a flag when you print the text to indicate that you've already >> printed it, and don't print it again if the flag is set. When it's no >> longer 12:00:00, reset the flag. >> >> That said, a busy while loop is probably the wrong way to do this, >> because it will run your CPU at 100%. Better would be to put the >> thread to sleep with time.sleep() calls or a real event loop with a >> timer event. >> >> Cheers, >> Ian > > Thank you Ian, > > what if I wait for other conditions if I use time.sleep for 1 sec? it > means that all the program is sleeping for a sec. You can sleep for less than a second. 0.2 seconds or so allows a pretty nice response time while still limiting how much your script will spin the CPU.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Run once while loop Ian Kelly <ian.g.kelly@gmail.com> - 2012-04-03 15:48 -0600
csiph-web