def optionally_serialize_and_write(state: Union[types.State, str], ws): # if not already serialized if not isinstance(state, str): state = unpack(state) state = json.dumps(state, cls=JSONEncoder) ws.send(state)
def _write_log_state(queue, path): with path.open("w", encoding="utf-8") as f: while True: state = queue.get() if type(state) is Client.QueueDone: break if not isinstance(state, str): state = unpack(state) state = json.dumps(state, cls=JSONEncoder) f.write(f"{state}\n")