[Twisted-Python] problem with Twisted and Processing

davy zhang davyzhang at gmail.com
Thu Oct 16 09:21:35 EDT 2008


I used Processing package for python 2.5 which became an official
package of python 2.6 named multipleprocess. 'Cause the twisted for
python 2.6 is not ready, I'm still using python 2.5 on windows
Here's the problem the code below is pretty simple and works fine
until I tried to get access of the first element in the list, I can
even print the whole list, but i just can not get the elements inside.
I guess there's something get conflicted in these two packages, anyone
knows why?

To reproduce the error, run the code below with twisted and processing
package and python 2.5, open a telnet client to open the localhost
9999,send the message ,hit carriage return.

thanks a lot for any hints


from twisted.protocols import basic
from twisted.internet import reactor
import time

from processing import Process,Manager

def sender(list):
    while 1:
        if len(list) > 0:
            print list[0]
        time.sleep(1)



class MyChat(basic.LineReceiver):
    def connectionMade(self):
        print "Got new client!"
        self.factory.clients.append(self)

    def connectionLost(self, reason):
        print "Lost a client!"
        self.factory.clients.remove(self)

    def lineReceived(self, line):
        print "received", repr(line)
        for c in self.factory.clients:
            c.message(line)
        d = {'client':self,'msg':line}
        msgList.append(d)

    def message(self, message):
        self.transport.write(message + '\n')


from twisted.internet import protocol
from twisted.application import service, internet

if __name__  == '__main__':
    factory = protocol.ServerFactory()
    factory.protocol = MyChat
    factory.clients = []
    reactor.listenTCP(9999,factory)

    manager = Manager()
    msgList = manager.list()

    p = Process(target=sender,args=(msgList,))
    p.start()
    reactor.run()




More information about the Twisted-Python mailing list