Stdoutflush: Flushing stdout to avoid issues with 64k char limits

This commit is contained in:
Kondal Kolipaka 2019-04-03 13:48:10 +05:30 committed by bot
parent c404f8b6e9
commit bc48a9c92f

View file

@ -78,9 +78,11 @@ def run_server(kconfig, sdkconfig, default_version=MAX_PROTOCOL_VERSION):
# V1: no 'visibility' key, send value None for any invisible item
values_dict = dict((k, v if visible_dict[k] else False) for (k,v) in config_dict.items())
json.dump({"version": 1, "values": values_dict, "ranges": ranges_dict}, sys.stdout)
sys.stdout.flush()
else:
# V2 onwards: separate visibility from version
json.dump({"version": default_version, "values": config_dict, "ranges": ranges_dict, "visible": visible_dict}, sys.stdout)
sys.stdout.flush()
print("\n")
while True:
@ -92,6 +94,7 @@ def run_server(kconfig, sdkconfig, default_version=MAX_PROTOCOL_VERSION):
except ValueError as e: # json module throws JSONDecodeError (sublcass of ValueError) on Py3 but ValueError on Py2
response = {"version": default_version, "error": ["JSON formatting error: %s" % e]}
json.dump(response, sys.stdout)
sys.stdout.flush()
print("\n")
continue
before = confgen.get_json_values(config)
@ -141,6 +144,7 @@ def run_server(kconfig, sdkconfig, default_version=MAX_PROTOCOL_VERSION):
print("Error: %s" % e, file=sys.stderr)
response["error"] = error
json.dump(response, sys.stdout)
sys.stdout.flush()
print("\n")