Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22635 > unrolled thread

Re: Run once while loop

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-04-03 14:45 -0600
Last post2012-04-03 14:45 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Run once while loop Ian Kelly <ian.g.kelly@gmail.com> - 2012-04-03 14:45 -0600

#22635 — Re: Run once while loop

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-04-03 14:45 -0600
SubjectRe: Run once while loop
Message-ID<mailman.1296.1333485940.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web