Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use utf-8 encoding for Json #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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