[Stackless] Q2: Uthread's 'Thread' class

Ixokai ixokai at myseraph.org
Fri Apr 13 01:38:22 CEST 2001

> Ixokai wrote:
> > From the microthread documentation: "When threads are created using the
> > Thread class, the first argument of the thread's function will be the
> > instance"

Just van Rossum wrote:
> I'm not sure, but it looks like the doco on
> http://world.std.com/~wware/uthread.html is still based on the original
> module. The above certainly doesn't apply to the current version...

Ahh. That explains why I was getting confused, I was using the uthread.py as
additional-documentation but still mostly refeering to the webpage. :)

Unfortunately, I still can't quite get it to add new thread objects into the
mix from one which already exists.

Stripped code follows; in it, the Client.run() never gets called, dispite
the uthread.new(client.run) in the connection bit of the Server process. I
think i'm just adding new threads the wrong way. :)


ClientList, ThreadList = [], []

class Server:
    def __init__(self, port = 3123):
          Server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          Server.bind( ("", port) )
          self._Server = Server
          if __debug__:
               print "Server process started."
         self.MessageQueue = uthread.Queue()

   def start(self, queue=1):
        if __debug__:
               print "Listening..."

        while 1:
               connection, info = self._Server.accept()
               if __debug__:
                    print "Got connection from", info
               client = Client(connection)
               th = uthread.new(client.run)


class Client:
    def __init__(self, *args, **kwargs):
          self.args = args
          self.kwargs = kwargs
          print "Client is running!"
    def run(self,instance,*args,**kwargs):
          print "Instance is:",instance,"Args are:", args, "Kwargs are:",

if __name__ == '__main__':
     print "You are in main!"
     s = Server()

Stackless mailing list
Stackless at starship.python.net

More information about the Stackless mailing list