DamjanDimitrioski
August 31st, 2007, 10:40 PM
Hi! :)
The program is separated in two modules:
Module I>
#! /usr/bin/env python
# -*- coding: utf-8 -*
# -*- Mode: Python -*-
import sys
import time
import threading
class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
time.sleep(self.runTime)
class CountDownTimer(Timer):
r = 0
def run(self):
counter = self.runTime
for sec in range(self.runTime):
time.sleep(1.0)
counter -= 1
self.r = 1
def now_it_is():
return r
def go(t):
c = CountDownTimer(t)
c.start()
Module II>
#! /usr/bin/env python
# -*- coding: utf-8 -*
# -*- Mode: Python -*-
from timerche import go
from timerche import CountDownTimer
odi(5)
while CountDownTimer.now_it_is() == 0:
print "not now."
else:
print "Done."
Now the proble is, i want to open from the first module, the timer module, and the timer i need to tell the first module when he is done, how can i code that, or if my code from above is ok, i mean the algorythm of it, then what is the error, i think that in timer module, the public var r is always 0, i tried 100 ways, it's still 0.
Any solutions?
The program is separated in two modules:
Module I>
#! /usr/bin/env python
# -*- coding: utf-8 -*
# -*- Mode: Python -*-
import sys
import time
import threading
class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
time.sleep(self.runTime)
class CountDownTimer(Timer):
r = 0
def run(self):
counter = self.runTime
for sec in range(self.runTime):
time.sleep(1.0)
counter -= 1
self.r = 1
def now_it_is():
return r
def go(t):
c = CountDownTimer(t)
c.start()
Module II>
#! /usr/bin/env python
# -*- coding: utf-8 -*
# -*- Mode: Python -*-
from timerche import go
from timerche import CountDownTimer
odi(5)
while CountDownTimer.now_it_is() == 0:
print "not now."
else:
print "Done."
Now the proble is, i want to open from the first module, the timer module, and the timer i need to tell the first module when he is done, how can i code that, or if my code from above is ok, i mean the algorythm of it, then what is the error, i think that in timer module, the public var r is always 0, i tried 100 ways, it's still 0.
Any solutions?