Files
pycapnp/examples/thread_client.py
Jacob Alexander 255119b838 Updating to capnproto v0.8.0
- Includes some test stabilization
- Fixes manylinux2010 build issues (linker flag order due to old gcc)
- More rigorous python setup.py clean
- Requires capnproto v0.8.0 or greater
- Including system libcapnp include path for import (e.g. import
  stream_capnp)
- Bundle libcapnp .capnp files when not using system libcapnp
- Removing more distutils usage. Now using pkg-config to determine the
  system version of libcapnp (mainly for Linux, but should work on macOS
  with brew)
- Removed dead code

Resolves issues #215 #216 #217
Lots of fixes for Issue #218 (all sorts of retry methods needed for
GitHub Actions)
2020-06-08 11:49:17 -07:00

60 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
from __future__ import print_function
import argparse
import threading
import time
import capnp
import thread_capnp
capnp.remove_event_loop()
capnp.create_event_loop(threaded=True)
def parse_args():
parser = argparse.ArgumentParser(usage='Connects to the Example thread server \
at the given address and does some RPCs')
parser.add_argument("host", help="HOST:PORT")
return parser.parse_args()
class StatusSubscriber(thread_capnp.Example.StatusSubscriber.Server):
'''An implementation of the StatusSubscriber interface'''
def status(self, value, **kwargs):
print('status: {}'.format(time.time()))
def start_status_thread(host):
client = capnp.TwoPartyClient(host, nesting_limit=64)
cap = client.bootstrap().cast_as(thread_capnp.Example)
subscriber = StatusSubscriber()
promise = cap.subscribeStatus(subscriber)
promise.wait()
def main(host):
client = capnp.TwoPartyClient(host, nesting_limit=64)
cap = client.bootstrap().cast_as(thread_capnp.Example)
status_thread = threading.Thread(target=start_status_thread, args=(host,))
status_thread.daemon = True
status_thread.start()
print('main: {}'.format(time.time()))
cap.longRunning().wait()
print('main: {}'.format(time.time()))
cap.longRunning().wait()
print('main: {}'.format(time.time()))
cap.longRunning().wait()
print('main: {}'.format(time.time()))
if __name__ == '__main__':
main(parse_args().host)