[Tutor] While Loop and Threads
Oğuzhan Öğreden
oguzhanogreden at gmail.com
Sun Jul 13 13:23:52 CEST 2014
Hi,
I've been practicing with multithreading and gtk for a while and recently
have observed something I can't quite grasp.
This is basically a timer with a settings window and a countdown window
which is produced after setting_window passes necessary arguments to thread.
I have a while loop which counts time, inside the thread, while variable
"runner" is True, which looks like this:
def run(self):
cycle = ['work', 'break', 'long_break']
cycle = cycle[:2]*self.workn+cycle[3]
self.runner = True
sec_count = timedelta(seconds=1)
while self.runner == True:
for i in cycle:
self.setState(i)
print('Start:', i, datetime.now())
while self.end_time > datetime.now():
time.sleep(1)
self.duration -= sec_count
self.count[self.state] += 1
And I want countdown to stop when countdown_window receives delete event,
thus I have a countdown_window.stop() function which is defined as follows:
def stop(self, *args):
pom.count[pom.state] -= 1
pom.runner = False # refers to the runner of the thread.
print(pom.runner) # prints False,
Gtk.main_quit()
What I expect to happen is that while loop to break, but it does not.
Any suggestions?
Best,
Oğuzhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140713/b9678fc5/attachment.html>
More information about the Tutor
mailing list