A server answers on one or more interfaces, and a client calls it; neither starts a thread.
import threading
import ucall
server = ucall.Server(ucall.Interface("127.0.0.1:0"))
@server.get("/hello/{name}")
def hello(name: str, excited: bool = False):
return f"Hello, {name}{'!' if excited else ''}"
runner = threading.Thread(target=server.run)
runner.start()
client = ucall.Client(connections=1)
response = client.get(f"http://{server.addresses[0]}/hello/world?excited=yes")
server.stop()
runner.join()
assert bytes(response.body) == b"Hello, world!"run serves the one event loop on the thread the application lent it, the client blocks in get until its response arrives, and stop releases the serving thread.