def print(*args, **kwargs): """Like builtin print(), but synchronized across multiple threads, and adds a timestamp. """ timestamped = kwargs.pop('timestamped', True) t = timestamp() if timestamped else None print_queue.put((t, args, kwargs))
def _recorder_worker(self): while True: occ = self._record_queue.get() if occ is None: self._record_queue.task_done() break self._accepting_new.wait() with self._recorded_new: occ.timeline = self occ.timestamp = timestamp() occ.index = next(self._index_iter) if self._last is None: self._beginning = occ self._last = occ else: occ.previous = self._last self._last._next = occ self._last = occ self._recorded_new.notify_all() self._record_queue.task_done()