How to do a callback sort of thing with pyAmf

View: New views
6 Messages — Rating Filter:   Alert me  

How to do a callback sort of thing with pyAmf

by Mike Dickson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?  

Any pointers or guidance greatly appreciated.

Mike (wishing python had continuations)

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Parent Message unknown Re: How to do a callback sort of thing with pyAmf

by Andrew Francis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

Re: How to do a callback sort of thing with pyAmf

by Mike Dickson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Andrew.  That gets me pointed in the right direction.  I've not
used Twisted but wanted to look at it so sounds like the time is right.


Again, thanks for the help and the very quick response!

Mike

On Tue, 2009-05-12 at 18:24 +0000, Andrew Francis wrote:

> 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

Re: How to do a callback sort of thing with pyAmf

by lists-144 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 12 May 2009, at 19:24, Andrew Francis wrote:

>> [snip]
>
> 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."

I believe that example was posted on our wiki, see http://pyamf.org/wiki/StacklessPythonTwisted

Cheers,

Thijs


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment

Parent Message unknown Re: How to do a callback sort of thing with pyAmf

by Andrew Francis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Thijs:

That was a year ago, when I was still learning the ropes. Give me a week and a bit so I can write more interesting examples. I think guys like Mike need more client side stuff.

Cheers,
Andrew


--- On Wed, 5/13/09, Thijs Triemstra | Collab <lists@...> wrote:

> From: Thijs Triemstra | Collab <lists@...>
> Subject: Re: [pyamf-users] How to do a callback sort of thing with pyAmf
> To: "PyAMF general discussion" <users@...>
> Date: Wednesday, May 13, 2009, 11:07 AM
>
> On 12 May 2009, at 19:24, Andrew Francis wrote:
>
> >> [snip]
> >
> > 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."
>
> I believe that example was posted on our wiki, see http://pyamf.org/wiki/StacklessPythonTwisted
>
> Cheers,
>
> Thijs
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>


     
_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How to do a callback sort of thing with pyAmf

by lists-144 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Andrew, looking forward to any examples you can provide. Feel free to open tickets for them so we can integrate them into the documentation/examples etc.

Cheers,

Thijs

On 14 May 2009, at 20:01, Andrew Francis wrote:


Hi Thijs:

That was a year ago, when I was still learning the ropes. Give me a week and a bit so I can write more interesting examples. I think guys like Mike need more client side stuff.

Cheers,
Andrew


--- On Wed, 5/13/09, Thijs Triemstra | Collab <lists@...> wrote:

From: Thijs Triemstra | Collab <lists@...>
Subject: Re: [pyamf-users] How to do a callback sort of thing with pyAmf
To: "PyAMF general discussion" <users@...>
Date: Wednesday, May 13, 2009, 11:07 AM

On 12 May 2009, at 19:24, Andrew Francis wrote:

[snip]

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."

I believe that example was posted on our wiki, see http://pyamf.org/wiki/StacklessPythonTwisted

Cheers,

Thijs

-----Inline Attachment Follows-----

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment