Python Bridge Client - connect call blocks?

107 views
Skip to first unread message

jchonphoenix

unread,
Aug 18, 2012, 3:11:02 PM8/18/12
to Bridge
Hello,

I'm trying to use Bridge to write simple pub/sub.

The python client, however, calls connect() at the end and then spins
in an IOLoop. This blocks. Once I've "connected" a client, does this
mean I can no longer send messages to the bridge server? (if this is
the case that makes no sense).

I assume I'm misunderstanding how I should be using the python client?
Can someone throw up an example?

I've also noticed that in the JS api, connect doesn't block so the
client can make calls after connection. Am I missing something?

-Jon

Rafael Garcia

unread,
Aug 18, 2012, 3:21:45 PM8/18/12
to bridge...@googlegroups.com
We spawn a separate thread for the bridge connect() call. It's not pretty, but it works:

class BridgeWrapper(object):
  def __init__(self):
    self.ready = False
    self.bridge = Bridge(api_key=BRIDGE_KEY)
    self.bridge_thread = Thread(target=self.connect_thread)
    self.bridge_thread.start()

  def set_ready(self, ready):
    self.ready = ready

  def connect_thread(self):
    set_ready_cb = partial(self.set_ready, True)
    self.bridge.connect(callback=set_ready_cb)

  def get_service(self, service):
    while (True):
      if self.ready: break
      time.sleep(1)
    return self.bridge.get_service(service)





--
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.
For more options, visit https://groups.google.com/groups/opt_out.



Jordan

unread,
Aug 18, 2012, 7:11:01 PM8/18/12
to bridge...@googlegroups.com
I actually have a very similar concern.  I'm using Bridge across the rest of my application, and think the framework is very elegant.  However, it's proven to be difficult in the following use case:

When I receive a call on SSH, I would like to query my servers to see if the user is actually allowed to make that command.  For this, I'm patching SSH to spawn a python process when an SSH command comes in, and do my logic there.  So the workflow is:
  1. Receive the SSH command
  2. Spawn a python process
  3. Make a call to my servers to decide whether the user is allowed to make that command
  4. If allowed to, run the command.  Otherwise, throw an error
If I want to make an RPC call in this python process, the process would never end because of the never-ending ioloop!  I just want to make the RPC call, get the result, and continue on with my life.  

Is there a good way of doing this in Bridge?
Reply all
Reply to author
Forward
0 new messages