where are the "class variables"?
Emile van Sebille
emile at fenx.com
Tue Sep 30 16:44:07 EDT 2003
"Dominik Kaspar" <dokaspar at student.ethz.ch> wrote in message
news:62e9c66e.0309301227.20505db6 at posting.google.com...
> maybe my question was badly formulated. i give it a new try:
> why does the following program give the output "0 0" and not "1 0"?
> why does it loop forever? and how could that problem be fixed?
As written, you have a local varaible running in method run that gets set
and never changes. The class variable you're looking for is Server.running,
like this:
import time, threading
class Server(threading.Thread):
running = 0
def run(self):
Server.running = 1
while Server.running:
print "do something here..."
time.sleep(5)
def stop(self):
Server.running = 0
server = Server()
server.start()
print server.running # should print "1"
server.stop()
--
Emile van Sebille
emile at fenx.com
More information about the Python-list
mailing list