[Twisted-Python] hang when using twisted

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Sep 18 10:05:57 MDT 2009


On 03:48 pm, gx1986 at mail.ustc.edu.cn wrote:
>
>
>I met some problem when writing twisted.
>
>The code is
>
>[snip]
>38
>39     def remoteCopyFile(HOST,filename = '4'):
>40            reactor.connectTCP(HOST,PORT,TSClientFactory(filename))
>41            reactor.run(installSignalHandlers=0)
>42            updateCurrentIPList.updateCurrentIPList(HOST)
>43 
>reactor.connectTCP(HOST,PORT,TSClientFactory('currentIP'))
>44            reactor.run(installSignalHandlers=0)
>45
>[snip]
>
>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 
reactor.

Jean-Paul




More information about the Twisted-Python mailing list