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


Groups > comp.lang.python > #22635

Re: Run once while loop

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'received:mail- lpp01m010-f46.google.com': 0.09; 'subject:while': 0.09; 'cc:addr :python-list': 0.10; 'thread': 0.12; 'times,': 0.14; 'wrote:': 0.19; 'trying': 0.20; 'least': 0.20; 'print': 0.21; 'header:In- Reply-To:1': 0.22; 'message-id:@mail.gmail.com': 0.24; 'run': 0.25; 'second': 0.25; 'cheers,': 0.26; 'cc:2**0': 0.26; 'said,': 0.27; 'set.': 0.27; 'cc:addr:python.org': 0.28; 'cpu': 0.28; 'text,': 0.28; 'hi,': 0.29; "i'm": 0.29; 'received:209.85.215.46': 0.30; 'reset': 0.31; 'received:209.85': 0.32; 'received:google.com': 0.32; 'probably': 0.32; 'pm,': 0.34; 'received:209': 0.35; 'text': 0.35; 'received:209.85.215': 0.37; 'but': 0.37; 'subject:: ': 0.37; 'header:Received:5': 0.40; 'this,': 0.40; 'indicate': 0.60; 'real': 0.61; '2012': 0.62; 'flag.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=9Q8WN1c3QbTCO5PGl36iBfAxogNWPJZAbmU0qMuETPM=; b=BTIKIF/sF/DAoaNvtEYlBamExPdtCpp2XifuICCbLDCqpLy4krSl85hBn1ndT0NRZM u4FPNkvaenf+SsTrOCwlabA1SL/wC/VvfNSCQbEh+E4FbvV7avfzQ2KVgIJgRm8dBJSH 5CTH/SRFi4EgwmaN3w2yEA9QcVrgMH1Hx6X321Qc2oE18hVwTV6BXnqabWNfNlWJf+Hn zFY31O/mFe/jHaPoyzoMhT1e/Nv4Fquf2xgUluog46NShXlPJrLxqBDcCE9W1ahk/iSq K/NV4SXPhD8nVyjYCCgqYeomJusK/6ro1o6G2fzwzKJqMMTQMTFPGv9S6vW9dZ9sMHbo blvg==
MIME-Version 1.0
In-Reply-To <7619907723400632495@unknownmsgid>
References <7619907723400632495@unknownmsgid>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 3 Apr 2012 14:45:08 -0600
Subject Re: Run once while loop
To Anatoli Hristov <tolidtm@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1296.1333485940.3037.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1333485940 news.xs4all.nl 6983 [2001:888:2000:d::a6]:33709
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22635

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web