
January 30th, 2013, 02:21 PM
|
|
Contributing User
|
|
Join Date: May 2009
Posts: 315
  
Time spent in forums: 3 Days 23 h 29 m 31 sec
Reputation Power: 7
|
|
Then multiprocessing/threading is the only option since you want to do 2 things at the same time, keep track of the time, and check for button presses. A simple example where the process is terminated after 5 seconds and the list's value is changed to simulate a button press or whatever, which could also return/exit from the function.
Code:
import time
from multiprocessing import Process
class TestClass():
def __init__(self):
self.ctr = 0
self.ctr_list=[0]
def test_f(self, name):
while True:
self.ctr += 1
print "test_f", self.ctr, name, self.ctr_list
time.sleep(0.5)
if __name__ == '__main__':
CT=TestClass()
p = Process(target=CT.test_f, args=('P',))
p.start()
time.sleep(2)
CT.ctr_list[0]=10
print "ctr_list", CT.ctr_list
## sleep for 5 seconds and terminate
time.sleep(5.0)
p.terminate()
|