<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I was thinking of threads but I just simply want to terminate a
(global) function after it has been running for more than 5 minutes
regardless of state.<br>
I was assuming I needed threads because it can calculate time elapsed
(that and im rather inexperienced with threads)<br>
Thanks again for your help!<br>
<br>
Diez B. Roggisch wrote:
<blockquote cite="mid45ls4mF7ch23U1@uni-berlin.de" type="cite">
<pre wrap="">Astan Chee wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
Im rather new to threads in python but Im trying to terminate a function
call (or the execution of the function) after a certain period of time
has passed.
Do i need to use threads with this? if i do, how do i go about doing it?
</pre>
</blockquote>
<pre wrap=""><!---->
Yes and no. As you didn't tell us muc about your actual problem, threads
might be what you need. But you _can't_ just stop a thread - however,
depending on what you do, you can for example regularly check for a flag
inside your function and then terminate:
class Foo(threading.Thread):
def __init__(self):
super(Foo, self).__init__()
self.setDaemon(True)
self.interrupted = False
def run(self):
while not self.interrupted:
do_some_work_but_make_sure_to_come_back_regularly()
f = Foo()
f.start()
time.sleep(10)
f.interrupted = True
Diez
</pre>
</blockquote>
</body>
</html>