@@ -271,21 +271,23 @@ def ensure(self, name, preparefunc, restart=False, persist_logs=True):
271
271
self .log .debug ("process %r started pid=%s" , name , pid )
272
272
stdout .close ()
273
273
274
- log_file_handle = open (info .logpath , errors = "ignore " )
274
+ log_file_handle = open (info .logpath , "rb " )
275
275
# keep track of all file handles so we can
276
276
# cleanup later during teardown phase
277
277
xresource .fhandles .append (log_file_handle )
278
278
279
279
if persist_logs :
280
280
# skip previous process logs
281
- process_log_block_handle = info .logpath .open ()
282
- lines = process_log_block_handle .readlines ()
281
+ process_log_block_handle = open (info .logpath , "rb" )
282
+ lines = [
283
+ str (line , "utf-8" ) for line in process_log_block_handle .readlines ()
284
+ ]
283
285
if lines :
284
286
proc_block_counter = sum (
285
287
1 for line in lines if XPROCESS_BLOCK_DELIMITER in line
286
288
)
287
289
for line in log_file_handle :
288
- if XPROCESS_BLOCK_DELIMITER in line :
290
+ if XPROCESS_BLOCK_DELIMITER in str ( line , "utf-8" ) :
289
291
proc_block_counter -= 1
290
292
if proc_block_counter <= 0 :
291
293
break
@@ -381,14 +383,12 @@ def pattern(self):
381
383
382
384
def startup_check (self ):
383
385
"""Used to assert process responsiveness after pattern match"""
384
-
385
386
return True
386
387
387
388
def wait_callback (self ):
388
389
"""Assert that process is ready to answer queries using provided
389
390
callback funtion. Will raise TimeoutError if self.callback does not
390
391
return True before self.timeout seconds"""
391
-
392
392
while True :
393
393
sleep (0.1 )
394
394
if self .startup_check ():
@@ -404,7 +404,6 @@ def wait_callback(self):
404
404
405
405
def wait (self , log_file ):
406
406
"""Wait until the pattern is mached and callback returns successful."""
407
-
408
407
self ._max_time = datetime .now () + timedelta (seconds = self .timeout )
409
408
lines = map (self .log_line , self .filter_lines (self .get_lines (log_file )))
410
409
has_match = any (std .re .search (self .pattern , line ) for line in lines )
@@ -413,23 +412,20 @@ def wait(self, log_file):
413
412
414
413
def filter_lines (self , lines ):
415
414
"""fetch first <max_read_lines>, ignoring blank lines."""
416
-
417
415
non_empty_lines = (x for x in lines if x .strip ())
418
416
return itertools .islice (non_empty_lines , self .max_read_lines )
419
417
420
418
def log_line (self , line ):
421
419
"""Write line to process log file."""
422
-
423
420
self .process .log .debug (line )
424
421
return line
425
422
426
423
def get_lines (self , log_file ):
427
424
"""Read and yield one line at a time from log_file. Will raise
428
425
TimeoutError if pattern is not matched before self.timeout
429
426
seconds."""
430
-
431
427
while True :
432
- line = log_file .readline ()
428
+ line = str ( log_file .readline (), "utf-8" )
433
429
434
430
if not line :
435
431
std .time .sleep (0.1 )
0 commit comments