Fix up examples
This commit is contained in:
@@ -61,6 +61,7 @@ void check_py_error() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: need to decref error_func as well on successful run
|
||||
PyObject * wrapPyFunc(PyObject * func, PyObject * arg) {
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func, arg, NULL);
|
||||
Py_DECREF(func);
|
||||
|
||||
@@ -1581,6 +1581,10 @@ cdef class RpcServer:
|
||||
def __dealloc__(self):
|
||||
del self.thisptr
|
||||
|
||||
def run_forever(self):
|
||||
p = PromiseFulfillerPair()
|
||||
self.loop.wait(p)
|
||||
|
||||
# TODO: add restore functionality here?
|
||||
|
||||
cdef class FdAsyncIoStream:
|
||||
|
||||
@@ -8,8 +8,8 @@ class Server:
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, context):
|
||||
context.results.x = str(context.params.i * 5 + self.val)
|
||||
def foo(self, i, **kwargs):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
def example_simple_rpc():
|
||||
def _restore(ref_id):
|
||||
@@ -17,10 +17,9 @@ def example_simple_rpc():
|
||||
|
||||
loop = capnp.EventLoop()
|
||||
|
||||
import os
|
||||
read, write = os.pipe()
|
||||
read_stream = capnp.FdAsyncIoStream(write)
|
||||
write_stream = capnp.FdAsyncIoStream(read)
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
read_stream = capnp.FdAsyncIoStream(read.fileno())
|
||||
write_stream = capnp.FdAsyncIoStream(write.fileno())
|
||||
|
||||
restorer = capnp.Restorer(capability.TestSturdyRefObjectId, _restore)
|
||||
server = capnp.RpcServer(loop, write_stream, restorer)
|
||||
|
||||
@@ -8,8 +8,8 @@ class Server:
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, context):
|
||||
context.results.x = str(context.params.i * 5 + self.val)
|
||||
def foo(self, i, **kwargs):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
def restore(ref_id):
|
||||
return test_capnp.TestInterface.new_server(Server(100))
|
||||
@@ -29,8 +29,7 @@ def example_server(host='localhost', port=49999):
|
||||
restorer = capnp.Restorer(test_capnp.TestSturdyRefObjectId, restore)
|
||||
server = capnp.RpcServer(loop, stream, restorer)
|
||||
|
||||
waiter = capnp.PromiseFulfillerPair()
|
||||
loop.wait(waiter)
|
||||
server.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user