[Twisted-web] Using Twisted to process a pool of messages

AmirBehzad Eslami behzad.eslami at gmail.com
Sun Oct 16 10:34:07 EDT 2011

Dear List,

i'm a PHP developer, and I'm very new to the world of Python and Twisted.
When it comes to use Twisted, my mind is unable to go beyond the
Top-To-Down Code execution model of PHP... Help!

i've been asked to write a service to process a list of SMS-messages, and send
each person a response. The messages are located on a PostgreSQL database
at a remote server.

Inside an infitie loop in Python, I call a single URL every 5 seconds, which
gives me an array of messages in JSON format. This URL has a special
format, which a parameter, named "last_sms_id".

URL: /give_me_messages.php?last_sms_id=XXX

In the Python script, I set a value to this paramter to tell the Remote Script
to only give me new messages, and ignore the old ones which I have
already recieved. It means that I must update last_sms_id after
processing each message.

The URL finally returns an array of messages.
i'm responsbile to process this array, and based on contents of each
message, call
a new URL, which doesn't matter for now.

Now I'm asked to use Twisted to make my python script asynchronous.
Well, I was  PHP Programmer. I'm wondering how this application could
become asynchronous.

Let me explain.
If the first call to the above URL fails to recieve content for some reason,
what will happen? Does asynchronous mean that Python will invoke
a new URL to the same URL again? or It will make a new URL call?
How can I handle "last_sms_id" during these asynchronous calls?

Thank you in advance,

More information about the Twisted-web mailing list