@@ -610,76 +610,73 @@ def run(self):
610610 self ._analysis_ref = analysis
611611 # Check kill flag after storing the reference in case
612612 # stop() was called between thread start and here.
613- if self ._kill .is_set ():
614- # analysis.__exit__ will send 'stop' automatically
615- pass
616- else :
617- for info in analysis :
618-
619- if self ._kill .is_set ():
620- break
613+ if not self ._kill .is_set ():
614+ for info in analysis :
621615
622- try :
623- line_number = int (info .get ('multipv' , 1 ))
624- depth = int (info ['depth' ]) if 'depth' in info else self .depth
625- score = self .score
626- if 'score' in info :
627- score = int (
628- info ['score' ].relative .score (mate_score = 32000 )
629- ) / 100
630- elapsed = info ['time' ] if 'time' in info else \
631- time .perf_counter () - start_time
632- pv = None
633-
634- if 'pv' in info and not ('upperbound' in info or
635- 'lowerbound' in info ):
636- self .pv = info ['pv' ][0 :self .pv_length ]
637-
638- if self .is_nomove_number_in_variation :
639- pv = self .short_variation_san ()
640- else :
641- pv = self .board .variation_san (self .pv )
642-
643- if line_number == 1 :
644- self .bm = info ['pv' ][0 ]
645-
646- if line_number == 1 and depth is not None :
647- self .depth = depth
648- if line_number == 1 and score is not None :
649- self .score = score
650- if line_number == 1 :
651- self .time = elapsed
652- if pv is not None :
653- self .pv = pv
654-
655- if score is not None and pv is not None and depth is not None :
656- if self .multipv > 1 :
657- info_to_send = \
658- '{} | {:+5.2f} | {} | {:0.1f}s | {} multipv_info' .format (
659- line_number , score , depth , elapsed , pv )
660- else :
661- info_to_send = \
662- '{:+5.2f} | {} | {:0.1f}s | {} info_all' .format (
663- score , depth , elapsed , pv )
664- self .eng_queue .put ('{}' .format (info_to_send ))
665-
666- # Send stop if movetime is exceeded
667- if not is_time_check \
668- and self .tc_type not in ('fischer' , 'delay' , 'infinite' ) \
669- and time .perf_counter () - start_time >= \
670- self .base_ms / 1000 :
671- logging .info ('Max time limit is reached.' )
672- is_time_check = True
616+ if self ._kill .is_set ():
673617 break
674618
675- # Send stop if max depth is exceeded
676- if 'depth' in info :
677- if int (info ['depth' ]) >= self .max_depth \
678- and self .max_depth != MAX_DEPTH :
679- logging .info ('Max depth limit is reached.' )
619+ try :
620+ line_number = int (info .get ('multipv' , 1 ))
621+ depth = int (info ['depth' ]) if 'depth' in info else self .depth
622+ score = self .score
623+ if 'score' in info :
624+ score = int (
625+ info ['score' ].relative .score (mate_score = 32000 )
626+ ) / 100
627+ elapsed = info ['time' ] if 'time' in info else \
628+ time .perf_counter () - start_time
629+ pv = None
630+
631+ if 'pv' in info and not ('upperbound' in info or
632+ 'lowerbound' in info ):
633+ self .pv = info ['pv' ][0 :self .pv_length ]
634+
635+ if self .is_nomove_number_in_variation :
636+ pv = self .short_variation_san ()
637+ else :
638+ pv = self .board .variation_san (self .pv )
639+
640+ if line_number == 1 :
641+ self .bm = info ['pv' ][0 ]
642+
643+ if line_number == 1 and depth is not None :
644+ self .depth = depth
645+ if line_number == 1 and score is not None :
646+ self .score = score
647+ if line_number == 1 :
648+ self .time = elapsed
649+ if pv is not None :
650+ self .pv = pv
651+
652+ if score is not None and pv is not None and depth is not None :
653+ if self .multipv > 1 :
654+ info_to_send = \
655+ '{} | {:+5.2f} | {} | {:0.1f}s | {} multipv_info' .format (
656+ line_number , score , depth , elapsed , pv )
657+ else :
658+ info_to_send = \
659+ '{:+5.2f} | {} | {:0.1f}s | {} info_all' .format (
660+ score , depth , elapsed , pv )
661+ self .eng_queue .put ('{}' .format (info_to_send ))
662+
663+ # Send stop if movetime is exceeded
664+ if not is_time_check \
665+ and self .tc_type not in ('fischer' , 'delay' , 'infinite' ) \
666+ and time .perf_counter () - start_time >= \
667+ self .base_ms / 1000 :
668+ logging .info ('Max time limit is reached.' )
669+ is_time_check = True
680670 break
681- except Exception :
682- logging .exception ('Failed to parse search info.' )
671+
672+ # Send stop if max depth is exceeded
673+ if 'depth' in info :
674+ if int (info ['depth' ]) >= self .max_depth \
675+ and self .max_depth != MAX_DEPTH :
676+ logging .info ('Max depth limit is reached.' )
677+ break
678+ except Exception :
679+ logging .exception ('Failed to parse search info.' )
683680 with self ._analysis_lock :
684681 self ._analysis_ref = None
685682 else :
0 commit comments