Skip to content

Commit 65771c5

Browse files
author
Andreas Maier
committed
Added support for pausing via stop+start.
Signed-off-by: Andreas Maier <andras.r.maier@gmx.de>
1 parent f15b23b commit 65771c5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

click_spinner/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class Spinner(object):
88
spinner_cycle = itertools.cycle(['-', '/', '|', '\\'])
99

1010
def __init__(self):
11-
self.stop_running = threading.Event()
12-
self.spin_thread = threading.Thread(target=self.init_spin)
11+
self.stop_running = None
12+
self.spin_thread = None
1313

1414
def start(self):
15+
self.stop_running = threading.Event()
16+
self.spin_thread = threading.Thread(target=self.init_spin)
1517
self.spin_thread.start()
1618

1719
def stop(self):

tests/test_spinner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@ def cli():
1515
result = runner.invoke(cli, [])
1616
assert result.exception is None
1717

18+
19+
def test_spinner_resume():
20+
@click.command()
21+
def cli():
22+
spinner = click_spinner.Spinner()
23+
spinner.start()
24+
for thing in range(10):
25+
pass
26+
spinner.stop()
27+
spinner.start()
28+
for thing in range(10):
29+
pass
30+
spinner.stop()
31+
32+
runner = CliRunner()
33+
result = runner.invoke(cli, [])
34+
assert result.exception is None
35+

0 commit comments

Comments
 (0)