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


Groups > comp.lang.python > #22640

Re: Run once while loop

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'received:mail- lpp01m010-f46.google.com': 0.09; 'second.': 0.09; 'subject:while': 0.09; 'cc:addr:python-list': 0.10; 'thread': 0.12; '>>>': 0.14; 'times,': 0.14; '0.2': 0.16; 'limiting': 0.16; 'sleeping': 0.16; '\xa0better': 0.16; 'wrote:': 0.19; 'allows': 0.20; '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; 'seconds': 0.26; 'cc:2**0': 0.26; 'said,': 0.27; 'set.': 0.27; 'script': 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; 'thank': 0.36; 'pretty': 0.36; 'received:209.85.215': 0.37; 'but': 0.37; 'subject:: ': 0.37; 'means': 0.38; 'header:Received:5': 0.40; 'this,': 0.40; 'less': 0.40; 'indicate': 0.60; 'real': 0.61; '2012': 0.62; '2012,': 0.84; 'cpu.': 0.84; 'flag.': 0.84; 'ian,': 0.84; 'sec.': 0.84; '3:00': 0.91
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:content-transfer-encoding; bh=kCzQuaCUVHVWOXz0AnwZG3CAgTlopLuaUnClolY528U=; b=DHFls7PLKsgisTr9HTMIevfE6Vjk0AC3MCuwskYTxuHliftiXyQQ/FbBGyL4Z3+hPc /Un6JXRzh+4ATAebIDWd9NlLfVw/oXYPdex4EqVvjO7+0bIYAOyvh16yJ6NBkigzU2in nzk4ZZgpQqxZ3xzl2w4V3RXH+8xO3ynwqqMNrNWG/MAb3h7zSNdQdtqmHXWnYtMNvWzQ Ih8jEb+FmSF3qtmOJ8Aohqx+h80fKOBL7Ds8XoE7dTO+NnIGGEigbWDEnAzDvKbQNJK+ T9Ambr/fK69uKh6VLAKf6bHP5nZC5agBX5kvxKwYMB9uDVeIlb3APY2I3qVzLqVq2SZV k+AQ==
MIME-Version 1.0
In-Reply-To <-5854393752682031995@unknownmsgid>
References <7619907723400632495@unknownmsgid> <CALwzidk_aLbsoaV4me87SzgzVuGgm1gX5qhgRDEYpCLvP1E_Aw@mail.gmail.com> <-5854393752682031995@unknownmsgid>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 3 Apr 2012 15:48:33 -0600
Subject Re: Run once while loop
To Anatoli Hristov <tolidtm@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.1301.1333489744.3037.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1333489744 news.xs4all.nl 6916 [2001:888:2000:d::a6]:55468
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22640

Show key headers only | View raw


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


Thread

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

csiph-web