[Twisted-Python] reactor.run hangs

giskard giskard at autistici.org
Mon Feb 15 04:37:08 EST 2010


Hi all,

i've moved reactor.run() out of the class and put in the main()

in the class i've:

  def addReactor(self):
    print 'dentro al run'
    factory = client.basicClientFactory(self.jid, self.option['jabber']['password'])
    print "factory initialized"
    factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
    print 'factory bootsraped'
    reactor.connectTCP(self.option['jabber']['server'], 5222, factory)

and in the main():

    jabber = MyJabber(options, to_irc)
    jabber.addReactor()
    reactor.run()

the ouput of the app,

edvige:jabber giskard$ python jabber2irc.py  config.yaml 
dentro al run
factory initialized
factory bootsraped

with tcpdum i see connection to jabber.org, but nothing else.
the presence is not set and so on..


Il giorno 15/feb/2010, alle ore 06.30, Alexandre Quessy ha scritto:

> Hello giskard,
> I suggest you leave the reactor.run() in the if __name__ == "__main__"
> of your application. It's a blocking call, until you call
> reactor.stop().
> Thats make things a lot easier when you need to merge many
> applications, classes, etc. together.
> 
> Next, to start your Jabber client, you should probably do it when
> reactor is running. To do so, you can use a reactor.callLater.
> 
> if __name__ == "__main__":
>  def _later():
>    # do stuff
>  reactor.callLater(0, _later)
>  reactor.run()
> 
> 
> 2010/2/14 Darren Govoni <darren at ontrenet.com>:
>> I believe reactor.run() never returns and always blocks the calling thread
>> until reactor.stop() is called, afterwhich you cannot call reactor.run()
>> again. Not sure if that helps you though.
>> 
>> On Sun, 2010-02-14 at 22:36 +0100, giskard wrote:
>> 
>> Hi all,
>> 
>> i think i'm not doing things in the right way:
>> 
>> http://paste.debian.net/59855/
>> 
>> this code implement a simple jabber client, if you remove the class
>> defnition
>> and run it (removing also the run def) it works!
>> 
>> but if i 'class' it and run via:
>> http://paste.debian.net/59856/
>> 
>> reactor.run() hangs.
>> 
>> where i'm wrong?
>> 
>> thank you in advance,
>> --
>> ciao,
>> giskard
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>> 
>> 
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>> 
>> 
> 
> 
> 
> -- 
> Alexandre Quessy
> http://alexandre.quessy.net/
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

--
ciao,
giskard






More information about the Twisted-Python mailing list