def _handle_match(self, pattern_obj, match):
"""
Handles a matched regex detected by :meth:`postprocess`. It calls
:obj:`Pattern.callback` and takes care of removing it from
:attr:`_patterns` (if it isn't sticky).
"""
if self._handling_match:
# Don't process anything if we're in the middle of handling a match.
# NOTE: This can happen when there's more than one thread,
# processes, or PeriodicCallback going on simultaneously. It seems
# to work better than threading.Lock()
return
self._handling_match = True
callback = partial(pattern_obj.callback, self, match.group())
self._call_callback(callback)
if self.debug:
# Turn on the fancy regex debugger/pretty printer
debug_callback = partial(
debug_expect, self, match.group(), pattern_obj.pattern)
self._call_callback(debug_callback)
if not pattern_obj.sticky:
self.unexpect(hash(pattern_obj)) # Remove it
self._handling_match = False
评论列表
文章目录