StoppableThread.is_stopped()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
c 2
b 0
f 2
dl 0
loc 7
rs 9.4285
1
"""Utility package for threads
2
3
.. Authors:
4
    Philippe Dessauw
5
    [email protected]
6
7
.. Sponsor:
8
    Alden Dima
9
    [email protected]
10
    Information Systems Group
11
    Software and Systems Division
12
    Information Technology Laboratory
13
    National Institute of Standards and Technology
14
    http://www.nist.gov/itl/ssd/is
15
"""
16
from threading import Thread, Event
17
18
19
class StoppableThread(Thread):
20
    """A thread with the ability to be remotely stopped
21
    """
22
23
    def __init__(self):
24
        Thread.__init__(self)
25
        self.stop_event = Event()
26
27
    def is_stopped(self):
28
        """Test if a thread is stopped
29
30
        Returns
31
            bool: True if stopped, False otherwise
32
        """
33
        return self.stop_event.isSet()
34
35
    def stop(self):
36
        """Stop the thread
37
        """
38
        self.stop_event.set()
39