Server-sent events
stream = EventStream() | A new stream. Return it from handle() to answer the request. It stays open after |
await stream.send(data) | Sends an event, with data as JSON. Raises ConnectionClosed once the viewer has left |
stream.on_close(callback) | Calls callback() when the viewer leaves |
from framework import ConnectionClosed | The exception, for except ConnectionClosed: |
Python
defaultdict(set) | A dict whose missing keys start out as empty sets. from collections import defaultdict |
s.add(x) / s.discard(x) | Adds x to a set, or removes it if it's there |
for x in list(s): | Loops over a copy, so s can change during the loop |
lambda: s.discard(x) | A function with no arguments, e.g. for a callback |
Postgres
Each run starts with an empty database, built from schema.sql. save_comment() adds a comment to it, and returns the comment.
Python · 50 linesStarter code · Ctrl/⌘ + Enter to run
SystemBroke
No runs yet.
Run the simulation to send this kata's traffic to your code. Hidden checks grade what it does.