File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -629,7 +629,7 @@ def __init__(self, frequency):
629
629
super (ThreadScheduler , self ).__init__ (frequency = frequency )
630
630
631
631
# used to signal to the thread that it should stop
632
- self .event = threading . Event ()
632
+ self .running = False
633
633
634
634
# make sure the thread is a daemon here otherwise this
635
635
# can keep the application running after other threads
@@ -638,21 +638,19 @@ def __init__(self, frequency):
638
638
639
639
def setup (self ):
640
640
# type: () -> None
641
+ self .running = True
641
642
self .thread .start ()
642
643
643
644
def teardown (self ):
644
645
# type: () -> None
645
- self .event . set ()
646
+ self .running = False
646
647
self .thread .join ()
647
648
648
649
def run (self ):
649
650
# type: () -> None
650
651
last = time .perf_counter ()
651
652
652
- while True :
653
- if self .event .is_set ():
654
- break
655
-
653
+ while self .running :
656
654
self .sampler ()
657
655
658
656
# some time may have elapsed since the last time
@@ -694,29 +692,27 @@ def __init__(self, frequency):
694
692
super (GeventScheduler , self ).__init__ (frequency = frequency )
695
693
696
694
# used to signal to the thread that it should stop
697
- self .event = threading . Event ()
695
+ self .running = False
698
696
699
697
# Using gevent's ThreadPool allows us to bypass greenlets and spawn
700
698
# native threads.
701
699
self .pool = ThreadPool (1 )
702
700
703
701
def setup (self ):
704
702
# type: () -> None
703
+ self .running = True
705
704
self .pool .spawn (self .run )
706
705
707
706
def teardown (self ):
708
707
# type: () -> None
709
- self .event . set ()
708
+ self .running = False
710
709
self .pool .join ()
711
710
712
711
def run (self ):
713
712
# type: () -> None
714
713
last = time .perf_counter ()
715
714
716
- while True :
717
- if self .event .is_set ():
718
- break
719
-
715
+ while self .running :
720
716
self .sampler ()
721
717
722
718
# some time may have elapsed since the last time
You can’t perform that action at this time.
0 commit comments