Discussion:
[capnproto] Passing and calling capabilities with pycapnp
c***@gmail.com
2018-02-14 22:45:42 UTC
Permalink
I have a use-case which is similar to streaming RPC to a server written in
C++ - here is a simplified example:

# Setup a client and connect it to our task server
client = capnp.TwoPartyClient('localhost:8000')
task_mgr = client.bootstrap().cast_as(schema.Task)

class Notifier(schema.Notifier.Server):
def notify(self, params, **kwargs):
print "notifying"

task = task_mgr.create(type=0)
n = Notifier()
task.add_notifier(n).wait()

task.run().wait()

capnp.wait_forever()

The C++ server will kick off the task which will call the notifier's notify
asynchronously. The C++ client works as expected (I get notify callbacks
when the task wants to notify). The python client seems to be unable to
pump the message loop. I see an example with a threaded client which
involves repeatedly chaining promises to make something like this work, but
is there an easier way?

I was hoping that the capnp.wait_forever() would take care of pumping the
loop and executing any callbacks, similar to
my kj::NEVER_DONE.wait(client.getWaitScope()); in the C++ client...
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
'Kenton Varda' via Cap'n Proto
2018-02-15 23:24:52 UTC
Permalink
It looks like capnp.wait_forever() is actually implemented as
kj::NEVER_DONE.wait() under the hood.

Can you provide more complete example code that we would be able to build
and run?

-Kenton
Post by c***@gmail.com
I have a use-case which is similar to streaming RPC to a server written in
# Setup a client and connect it to our task server
client = capnp.TwoPartyClient('localhost:8000')
task_mgr = client.bootstrap().cast_as(schema.Task)
print "notifying"
task = task_mgr.create(type=0)
n = Notifier()
task.add_notifier(n).wait()
task.run().wait()
capnp.wait_forever()
The C++ server will kick off the task which will call the notifier's
notify asynchronously. The C++ client works as expected (I get notify
callbacks when the task wants to notify). The python client seems to be
unable to pump the message loop. I see an example with a threaded client
which involves repeatedly chaining promises to make something like this
work, but is there an easier way?
I was hoping that the capnp.wait_forever() would take care of pumping the
loop and executing any callbacks, similar to my kj::NEVER_DONE.wait(client.getWaitScope());
in the C++ client...
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/capnproto.
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
c***@gmail.com
2018-03-28 22:18:58 UTC
Permalink
Hi Kenton,

Sorry for the delay, but I believe this was an issue with how I was using
pycapnp. It turns out that pycapnp's binding is very sensitive to the
naming of arguments. In the example above,

class Notifier(schema.Notifier.Server):
def notify(self, params, **kwargs):
print "notifying"

notify's "params" argument was named "data" in the capnp schema file.
After changing the name, everything works fine! Not sure what can be done
about this in a language like Python unfortunately...

-Cody
Post by 'Kenton Varda' via Cap'n Proto
It looks like capnp.wait_forever() is actually implemented as
kj::NEVER_DONE.wait() under the hood.
Can you provide more complete example code that we would be able to build
and run?
-Kenton
Post by c***@gmail.com
I have a use-case which is similar to streaming RPC to a server written
# Setup a client and connect it to our task server
client = capnp.TwoPartyClient('localhost:8000')
task_mgr = client.bootstrap().cast_as(schema.Task)
print "notifying"
task = task_mgr.create(type=0)
n = Notifier()
task.add_notifier(n).wait()
task.run().wait()
capnp.wait_forever()
The C++ server will kick off the task which will call the notifier's
notify asynchronously. The C++ client works as expected (I get notify
callbacks when the task wants to notify). The python client seems to be
unable to pump the message loop. I see an example with a threaded client
which involves repeatedly chaining promises to make something like this
work, but is there an easier way?
I was hoping that the capnp.wait_forever() would take care of pumping the
loop and executing any callbacks, similar to
my kj::NEVER_DONE.wait(client.getWaitScope()); in the C++ client...
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/capnproto.
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
Loading...