[Twisted-Python] hang when using twisted

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Sep 18 12:05:57 EDT 2009

On 03:48 pm, gx1986 at mail.ustc.edu.cn wrote:
>I met some problem when writing twisted.
>The code is
>39     def remoteCopyFile(HOST,filename = '4'):
>40            reactor.connectTCP(HOST,PORT,TSClientFactory(filename))
>41            reactor.run(installSignalHandlers=0)
>42            updateCurrentIPList.updateCurrentIPList(HOST)
>44            reactor.run(installSignalHandlers=0)
>The program print two "finished",then hang.
>If i delete the line 40 and 41  or delete the line 43 and 44 ,the 
>program become good.
>whether can't we use two "reactor.run()" in one function? why?
>Thank you!

Yes, you cannot call reactor.run() twice (anywhere in the same program - 
whether within one function or otherwise).  This is an minor 
implementation limitation which could fairly easily be lifted if anyone 
really wanted to.  However, there's not a lot of reason to bother. 
Instead of stopping the reactor after your first task and then starting 
it for your second task, just start your second task when the first one 
is done - don't stop the reactor and then start it again.  When you're 
done with everything and ready to exit, that's when you should stop the 


More information about the Twisted-Python mailing list