Skip to content

Commit c3bc6cb

Browse files
committed
Improve stop
1 parent 4c678a7 commit c3bc6cb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

glancesarena/glances3/plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ def stopped(self):
7676
@lockandrun
7777
def update(self, item):
7878
"""Simulate an plugin update method."""
79-
s = random.uniform(0, 10)
8079
logging.info('Update processe started')
81-
self._stats.append(item)
82-
t = Timer(s)
80+
# Simulate an update
81+
t = Timer(random.uniform(0, 5))
8382
while not t.finished() and not self.stopped():
8483
sleep(0.01)
84+
self._stats.append(item)
85+
# /Simulate an update
8586
if self.stopped():
8687
logging.info('Update processes stopped')
8788
else:

glancesarena/glances3/test01.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Nicolargo (08/2017)
66

77
import signal
8-
import sys
98
import threading
109
from plugin import Plugin
1110

@@ -28,16 +27,19 @@ def __init__(self):
2827
self.plugins_list.append(Plugin(name='plugin%s' % (i - 1)))
2928

3029
def update(self):
30+
# Init the threads list
3131
self.plugin_threads = []
3232
for i in range(0, 9):
3333
t = threading.Thread(name='plugin%s' % i,
3434
target=self.plugins_list[i].update,
3535
args=(i,))
3636
self.plugin_threads.append(t)
37+
# Start all the threads
3738
t.start()
39+
# Wait all the threads
40+
t.join()
3841

3942
def stop(self, signal, frame):
40-
print('CTRL-C pressed')
4143
for i in range(0, 9):
4244
self.plugins_list[i].stop()
4345

0 commit comments

Comments
 (0)