Discussion:
[capnproto] Callback does not work as expected
Jeffrey Qiu
2018-06-01 09:35:51 UTC
Permalink
The protocol is defined as:
interface Test {
interface Callback {
call @0 (id :UInt64) -> ();
}
runCallback @1 (cb : Callback) -> ();
}
The Callback is implemented in client side:
class CallbackImpl(callback_capnp.Test.Callback.Server):
def call(self, id, **kwargs):
print ("Call back from client, id = %s" % id)
In server side, it is defined as:
class Server(callback_capnp.Test.Server):
def runCallback(self, cb, **kwargs):
cb.call(1);
time.sleep(5)
cb.call(2);

From client side, run cap.runCallback(CallbackImpl()).wait()
The expected result is:
1. Call back from client, id = 1
2. 5 seconds sleep
3. Call back from client, id = 2
But actually result is:
1. 5 seconds sleep
2. Call back from client, id = 1
3. Call back from client, id = 2

What's the matter? How to implement the expect result?

-Jeffrey
--
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-06-01 20:53:59 UTC
Permalink
Hi Jeffrey,

Cap'n Proto uses event loop concurrency, not threading. When you call
time.sleep(5), the event loop doesn't run, so the call you just initiated
is not sent. You need to use capnp.getTimer(). Example:

https://github.com/capnproto/pycapnp/blob/master/examples/thread_server.py#L16

-Kenton
Post by Jeffrey Qiu
interface Test {
interface Callback {
}
}
print ("Call back from client, id = %s" % id)
cb.call(1);
time.sleep(5)
cb.call(2);
From client side, run cap.runCallback(CallbackImpl()).wait()
1. Call back from client, id = 1
2. 5 seconds sleep
3. Call back from client, id = 2
1. 5 seconds sleep
2. Call back from client, id = 1
3. Call back from client, id = 2
What's the matter? How to implement the expect result?
-Jeffrey
--
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...