Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pytracing/pytracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import json
import time
import threading
import logging
from contextlib import contextmanager

logger = logging.getLogger(__name__)

try:
from queue import Queue
except ImportError:
Expand All @@ -32,17 +35,19 @@ def __init__(self, terminator, input_queue, output_stream):

def _open_collection(self):
"""Write the opening of a JSON array to the output."""
self.output.write(b'[')
logger.debug('_open_collection')
self.output.write('[')

def _close_collection(self):
"""Write the closing of a JSON array to the output."""
self.output.write(b'{}]') # empty {} so the final entry doesn't end with a comma
logger.debug('_close_collection')
self.output.write('{}]') # empty {} so the final entry doesn't end with a comma

def run(self):
self._open_collection()
while not self.terminator.is_set() or not self.input.empty():
item = self.input.get()
self.output.write((json.dumps(item) + ',\n').encode('ascii'))
self.output.write(json.dumps(item) + ',\n')
self._close_collection()


Expand Down