python – How can my desktop application be notified of a state change on a remote server? – Education Career Blog

I’m creating a desktop application that requires authorization from a remote server before performing certain actions locally.

What’s the best way to have my desktop application notified when the server approves the request for authorization? Authorization takes 20 seconds average on, 5 seconds minimum, with a 120 second timeout.

I considered polling the server ever 3 seconds or so, but this would be hard to scale when I deploy the application more widely, and seems inelegant.

I have full control over the design of the server and client API. The server is using web.py on Ubuntu 10.10, Python 2.6.

,

Does the remote end block while it does the authentication? If so, you can use a simple select to block till it returns.

Another way I can think of is to pass a callback URL to the authentication server asking it to call it when it’s done so that your client app can proceed. Something like a webhook.

,

You need to do something asynchronous. I’ve always been a big fan of twisted, which is a framework for doing async networking in python. It supports a lot of common protocols and has the plumbing to roll your own. If twisted seems a bit overkill, you can compare other async frameworks here

Leave a Comment