sysom1/environment/1_sdk/cmg_base/utils.py

29 lines
753 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*- #
"""
Time 2023/3/18 12:37
Author: mingfeng (SunnyQjm)
Email mfeng@linux.alibaba.com
File utils.py
Description:
"""
import threading
class StoppableThread(threading.Thread):
"""Thread class with a stop() method
The thread itself has to check regularly for the stopped() condition.
"""
def __init__(self, group=None, target=None, **kwargs):
super().__init__(group, target, **kwargs)
self._stop_event = threading.Event()
def stop(self):
"""Notify the thread to exitasync"""
self._stop_event.set()
def stopped(self):
"""Determine whether the thread exits."""
return self._stop_event.is_set()