[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: How to let a loop run for a while before checking for break condition?
From: Sorin Schwimmer <sxn02 () yahoo ! com>
Date: 2006-08-28 18:57:07
Message-ID: 20060828185707.61402.qmail () web56004 ! mail ! re3 ! yahoo ! com
[Download RAW message or body]
I am thinking on something in the following form:
<code>
import time
import thread
delay=True
def fn()
global delay
time.sleep(<your_amount_of_time_in_seconds>)
delay=False
thread.start_new_thread(fn,())
while delay:
<statement 1>
<statement 2>
...
while <other_condition>:
<statement 1>
<statement 2>
...
</code>
Or, if you need to use "break", the second loop may be
something like:
<code>
while True:
<statement 1>
<statement 2>
...
if <other_condition>: break
<other_statements>
...
</code>
The two while loops have the same content, but the
first is terminated after a pre-determined amount of
time, while the second by another condition. Usually
the content of the too loops, being the same, is a
call to a function that does the actual work. In your
case, as time seems to be critical, you don't want to
spend it in function-call overheads, so you repeat
(cut'n'paste) the relevant code.
Of course, the price to be paid is in maintenance
headache: you'll have to make all the changes in both
loops, to keep consistency.
I hope this helps.
Sorin
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic