@@ -50,21 +50,35 @@ def cli_parser():
5050 }
5151
5252 # Serialize the command line args and the options to stdout
53- os .write (1 , pickle .dumps ([sys .argv [1 :], options ]))
53+ serialized_data = pickle .dumps ([sys .argv [1 :], options ])
54+ os .write (1 , serialized_data )
55+ # Ensure all data is written before process exits
56+ sys .stdout .flush ()
5457
5558 def parse (args ):
5659 log .debug ("Parsing argv: {0!r}" , args )
5760 try :
5861 try :
5962 # Run the CLI parser in a subprocess, and capture its output.
6063 output = subprocess .check_output (
61- [sys .executable , "-u" , cli_parser .strpath ] + args
64+ [sys .executable , "-u" , cli_parser .strpath ] + args ,
65+ stderr = subprocess .PIPE # Capture stderr to help with debugging
6266 )
6367
6468 # Deserialize the output and return the parsed argv and options.
65- argv , options = pickle .loads (output )
69+ try :
70+ argv , options = pickle .loads (output )
71+ except Exception as e :
72+ log .debug ("Failed to deserialize output: {0}, Output was: {1!r}" , e , output )
73+ raise
6674 except subprocess .CalledProcessError as exc :
67- raise pickle .loads (exc .output )
75+ log .debug ("Process exited with code {0}. Output: {1!r}, Error: {2!r}" ,
76+ exc .returncode , exc .output , exc .stderr )
77+ try :
78+ raise pickle .loads (exc .output )
79+ except Exception as e :
80+ log .debug ("Failed to deserialize error output: {0}, Output was: {1!r}" , e , exc .output )
81+ raise
6882 except EOFError :
6983 # We may have just been shutting down. If so, return an empty argv and options.
7084 argv , options = [], {}
0 commit comments