On Friday 18 June 2010 19:24:54 Glyph Lefkowitz wrote:
On Jun 18, 2010, at 8:25 AM, Szabolcs Balogh wrote:
Than how can I start checking for messages for different accounts (When I have finished checking the messages for the first account to start checking for the next account, and so on...)?
The whole *point* of the "reactor" is to allow multiple connections (and timed calls) to be serviced simultaneously.
When you have "finished checking messages" for the first account, presumably there is a callback of some kind; most likely 'connectionLost()'. In connectionLost, you can just call connectTCP again with a protocol factory pointed at the second account.
This is actually a FAQ:
<http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeTwis tedtalktomultipleclientsconnecttomultipleservers>
Hopefully this helps.
This is a hard question to answer in a way where the next asker will actually find the answer, since the answer is really "just call a method", and the asker needs to understand that they can call any of these methods at any time. If you have any idea as to how the FAQ could be improved so that you might have found your answer while searching around, please let us know :). For example: the way you phrased your requirement here, "When I have done X, start doing X", even *sounds* like an event-driven program - 'def iHaveFinishedChecking(self): next.startChecking()' - so you were clearly on the right track. Why did you think you needed to run the reactor again in order to accomplish this?
Using: twisted.internet.reactor.connectTCP(host, port, imapfactory, 4) twisted.internet.reactor.run() it works. But if I try: twisted.internet.reactor.run() twisted.internet.reactor.connectTCP(host, port, imapfactory, 4) it stops at run() and doesn't executes the connectTCP method. This is why I thought that first I have to execute connectTCP and then reactor.run()
Couldn't you use callLater to fire the first account check every N interval and then just attach the subsequent accounts for that interval as callbacks to the first check inside your callLater func?
I can't use the callLater, because I'm working on the engine part of an email client. So I need a "get_messages(imap_account)" method, which can be called from the GUI synchron or asynchron (pressed the check now button by the user) and checks for new messages for the account specified. So it needs to be as generally as possible and automatically doesn't do anything.