Hi Mike:
--- On Tue, 5/12/09, Mike Dickson <
mike.dickson@...> wrote:
> Is there a well known pattern for handling a case where a client
> should get notified when the state of a server/remote object
> changes? I figure I can make the client make a remote call that blocks
> on a condition variable in my server and wake it up when the data changes
> but that means a thread per client and I don't like how that
> scales?
Since I left my last gig, I haven't played with PyAMF. So here goes....
Like the Observer design pattern?
If I understand you correctly, perhaps you can poll the remote site with task.loopingCall(). If the loopingCall function detects a change,
it can create a Deferred and start the processing by doing a callback.
This way you are not creating threads.
pseudo code
"""
my application logic is in here
"""
def doSomething(result):
.....
"""
your polling/state change logic is here
"""
def poll():
state = yield client.getPage(...) #short-hand, an inlineCallback
if state != oldState:
oldState = state
deferred = defer.Deferred().addCallback(doSomething)
deferred.callback(result) # start the processing right away
in startup code
task = tasking.loopingCall(poll)
task.start(.01)
> Mike (wishing python had continuations)
You could use Stackless Python. About a year ago, I posted examples of how to use PyAMF with Stackless. Shameless plug: I also presented a talk at Pycon 2008 "Adventures in Stackless Python Twisted Integration."
Cheers,
Andrew
_______________________________________________
PyAMF users mailing list -
users@...
http://lists.pyamf.org/mailman/listinfo/users