in tensorboardX/tensorboardX/event_file_writer.py [0:0]
def run(self):
# Here wait on the queue until an data appears, or till the next
# time to flush the writer, whichever is earlier. If we have an
# data, write it. If not, an empty queue exception will be raised
# and we can proceed to flush the writer.
while True:
now = time.time()
queue_wait_duration = self._next_flush_time - now
data = None
try:
if queue_wait_duration > 0:
data = self._queue.get(True, queue_wait_duration)
else:
data = self._queue.get(False)
if data == self._shutdown_signal:
return
self._record_writer.write_event(data)
self._has_pending_data = True
except six.moves.queue.Empty:
pass
finally:
if data:
self._queue.task_done()
now = time.time()
if now > self._next_flush_time:
if self._has_pending_data:
# Small optimization - if there are no pending data,
# there's no need to flush, since each flush can be
# expensive (e.g. uploading a new file to a server).
self._record_writer.flush()
self._has_pending_data = False
# Do it again in flush_secs.
self._next_flush_time = now + self._flush_secs