Переглянути джерело

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

Kondal Kolipaka 6 роки тому
батько
коміт
bc48a9c92f
1 змінених файлів з 4 додано та 0 видалено
  1. 4 0
      tools/kconfig_new/confserver.py

+ 4 - 0
tools/kconfig_new/confserver.py

@@ -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")