@@ -300,6 +300,13 @@ def enqueue_output(out, queue):
300300 t .daemon = True
301301 t .start ();
302302
303+ log_job_output_file = None
304+ if 'log_job_output' in self .client_info and self .client_info ['log_job_output' ] is True :
305+ if 'log_dir' in self .client_info and self .client_info ['log_dir' ]:
306+ log_job_output = os .path .join (self .client_info ['log_dir' ], 'job_{}_{}' .format (self .job_data ['job_id' ], step_data ['step_num' ]))
307+ log_job_output_file = open (log_job_output , 'wb' )
308+ logger .info ('Writing job output to {}' .format (log_job_output ))
309+
303310 while proc .poll () is None :
304311 if self .canceled or self .stopped :
305312 logger .info ("Killing job\n " )
@@ -309,9 +316,14 @@ def enqueue_output(out, queue):
309316 break
310317
311318 output = self .get_output_from_queue (q )
312- if output and not over_max :
313- out .extend (output )
314- chunk_out .extend (output )
319+ if output :
320+ if not over_max :
321+ out .extend (output )
322+ chunk_out .extend (output )
323+ if log_job_output_file is not None :
324+ for chunk in output :
325+ log_job_output_file .write (chunk .encode ('utf-8' ))
326+ log_job_output_file .flush ()
315327
316328 # Don't worry that "out" might contain multibyte characters, we
317329 # just want a rough size check
@@ -343,9 +355,16 @@ def enqueue_output(out, queue):
343355 t .join () # make sure the step has no more output
344356
345357 # we might not have gotten everything
346- out .extend (self .get_output_from_queue (q , timeout = 0 ))
358+ remaining_output = self .get_output_from_queue (q , timeout = 0 )
359+ out .extend (remaining_output )
347360 if not step_data ['canceled' ] or keep_output :
348361 step_data ['output' ] = '' .join (out )
362+ if log_job_output_file is not None :
363+ if remaining_output :
364+ for chunk in remaining_output :
365+ log_job_output_file .write (remaining_output .encode ('utf-8' ))
366+ log_job_output_file .flush ()
367+ log_job_output_file .close ()
349368 step_data ['complete' ] = True
350369 step_data ['time' ] = int (time .time () - start_time ) #would be float
351370 return step_data
0 commit comments