Datetime in a callback

16 views
Skip to first unread message

Justin

unread,
Jul 16, 2012, 7:07:28 PM7/16/12
to bridge...@googlegroups.com
Since I'm on such a roll here and have your attention I'm gonna throw one more at you :)

My service is passing a datetime through a callback to the client. The client sees it as a Reference. I played around with it in an interpreter and dug into the python source a little, but haven't seen how to get the datetime value back. I do see methods on the datetime class, but not the value. What am I doing wrong?

Thanks

My simple example:

$ cat server.py
from configit import conf_from_file
from datetime import datetime
config = conf_from_file('../development.py')

from BridgePython import Bridge

class SimpleHandler(object):
    def simple(self, callback=None):
        if callback:
            callback(datetime.now())

bridge = Bridge(api_key=config.private_api_key)
bridge.publish_service('simple', SimpleHandler())

bridge.connect()

$ cat client.py 
from configit import conf_from_file
config = conf_from_file('../development.py')

from BridgePython import Bridge

bridge = Bridge(api_key=config.public_api_key)
client = None

def service_response(resp):
    print(resp)

service = bridge.get_service('simple')
service.simple(service_response)
"""
Prints out:
$ python client.py
<BridgePython.reference.Reference object at 0x10b84f8d0>

Haven't figured out how to get this Reference object to give me the datetime.
"""

Steve Wang

unread,
Jul 16, 2012, 7:29:06 PM7/16/12
to bridge...@googlegroups.com
Bridge doesn't allow you to use synchronous functions (i.e. those that
return a value), since that would involve waiting for the return
value. Generally, you can either pass the actual value (e.g. UNIX
time) over the wire, or you can provide a wrapper. Yet another option,
since you're working with python => python, is to extend the JSON
encoder/decoder (http://docs.python.org/library/json.html should be
helpful). This last way should allow you to pass Python objects over
the wire and see them as identical (i.e. cloned) objects (as opposed
to remote References).
> --
> You received this message because you are subscribed to the Google Groups
> "Bridge" group.
> To post to this group, send email to bridge...@googlegroups.com.
> To unsubscribe from this group, send email to
> bridge-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/bridge-users/-/seU1yTO6AokJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages