what thread-synch mech to use for clean exit from a thread
zhangweiwu at realss.com
zhangweiwu at realss.com
Sun Jul 14 22:32:52 EDT 2013
On Monday, July 15, 2013 10:27:45 AM UTC+8, Gildor Oronar wrote:
> What is the professional way in this case?
Hi. I am not a professional neither but I think a professional does this:
class CurrencyExchange():
def __init__(in_case_callback):
this.callback = in_case_callback
def __run__():
while time.time() - self.rate_timestamp < 5*3600:
... # update exchange rate
if success:
self.rate_timestamp == time.time()
time.sleep(60)
def main():
agio = CurrencyExchange(in_case = callback)
agio.start()
while agio.is_alive():
do_something_delicate(rate_supplied_by=agio)
Notice even if agio is no longer alive, it can still supply exchange rate for the last delicate_thing, only that it no longer updates punctually. This is semantic wrong, and I think it is the fault of python: how can something dead execute its method? In the API, thread.is_alive() should be renamed to thread.is_activate_and_on_his_own()
More information about the Python-list
mailing list