[Twisted-Python] newbe twisted xmpp load
Wrene Robyn
wrobyn at cox.net
Tue Mar 13 19:47:46 MDT 2007
OH! I get it,
I was under the impression that there was a different syntax for
reactor.run() if you were using a poll reactor like pollreactor.run()
or something. The code no longer throws up using import poll reactor.
I am still capping off at around 984 connections but I believe this
to be on os issue
On Mar 11, 2007, at 9:02 PM, Jean-Paul Calderone wrote:
> 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
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
More information about the Twisted-Python
mailing list