[Twisted-Python] newbe twisted xmpp load
Jean-Paul Calderone
exarkun at divmod.com
Sun Mar 11 19:02:31 MDT 2007
On Sun, 11 Mar 2007 19:43:15 -0400, Wrene Robyn <wrobyn at cox.net> wrote:
>Thanks for all your help thus far. Here is my code which does run with
>normal select reactor. How to switch it to use poll reactor? that is really
>the crux of my problem.
As in my previous post, you switch it to the poll reactor by importing and installing the poll reactor before the default reactor is imported and installed. You can do this by adding these two lines:
from twisted.internet import pollreactor
pollreactor.install()
to the program anywhere before the default reactor is imported. For example, you could add them before the "import sys" line.
>
>import sys
>import socket
>import time
>import resource
>from threading import Thread
>from twisted.words.protocols.jabber import client, jid
>from twisted.words.xish import domish
>from twisted.internet import reactor
>
>resource.setrlimit(8,[65000,65000])
>class testit():
>
> def authd(xmlstream):
> print "authenticated"
>
> presence = domish.Element(('jabber:client','presence'))
> xmlstream.send(presence)
> #xmlstream.addObserver('/message', debug)
> #xmlstream.addObserver('/presence', debug)
> #xmlstream.addObserver('/iq', debug)
>
> def debug(elem):
> print elem.toXml().encode('utf-8')
> print "="*20
Note that this code:
> for i in range(1,2000):
> print i
> myJid = jid.JID(str(i)+'@jbrsrvrnamt/twisted_words')
> factory = client.basicClientFactory(myJid, 'test')
> factory.addBootstrap('//event/stream/authd',authd)
> reactor.connectTCP('jbrsrvrname',5222,factory)
>
> reactor.run()
is all at the class definition level, so it is executed when the class
is defined. This means you are starting the reactor before the class
definition has even completed. You probably don't want to do this. All
the code after this point doesn't even get a chance to run until the
reactor stops.
>
>current = testit()
>current.start()
>
Jean-Paul
More information about the Twisted-Python
mailing list