[Twisted-Python] using ClientFactory from within a server

Greg greg at digitalinfo.net
Tue Sep 30 13:07:37 MDT 2003


Greg wrote:

>>>         reactor.connectTCP(host, port, factory2)
>>>         reactor.run()   
>>
>>
>>  Remove the above call to "reactor.run() and see what happens.
>>
>>>         print "Returned from sending email"
>>>         # ^ Never gets to this point
>>>   
>>
> Thanks. Now I am getting closer. But a strange (to me) thing happens. 
> When I connect to the Echo server and send it a string, it does 
> correctly run the MySMTP code. But it does not return and execute the 
> 'print "Returned from sending email"' statement until I connect to the 
> Echo server again and send another string. Any idea why this is 
> happening? Is there a way to disconnect factory2 from the reactor 
> after I have sent the "QUIT" string (or when 
> MySMTPClientFactory.clientConnectionLost() gets called)?

Never mind, I suck. I finally noticed that it was of course immediately 
returning from the reactor.connectTCP() and immediately printing 
"Returned from sending email", then getting around to actually running 
the MySMTPClientFactory stuff. I guess I have to learn about using 
deferreds. Thanks again for your previous help.





More information about the Twisted-Python mailing list