Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 43f24b8

Browse files
authored
Allow Pipeline to Restart After Stopped (#58)
Initially, the pipeline set the input source to None on a call to stop. This blocked the ability to start again without creating a new pipeline instance. There are certain situations where the user may want to halt the pipeline for a period longer than a pause, but stil be able to start again without restarting the main application.
1 parent 7383a3f commit 43f24b8

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

spokestack/pipeline.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def close(self) -> None:
3232
""" Closes the running pipeline """
3333
self.stop()
3434

35+
for stage in self._stages:
36+
stage.close()
37+
38+
self._stages.clear()
39+
self._input_source.close()
40+
3541
def activate(self) -> None:
3642
""" Activates the pipeline """
3743
self._context.is_active = True
@@ -50,6 +56,7 @@ def stop(self) -> None:
5056
""" Halts the pipeline """
5157
self._is_running = False
5258
self._input_source.stop()
59+
self._context.reset()
5360

5461
def pause(self) -> None:
5562
""" Stops audio input until resume is called """
@@ -68,23 +75,13 @@ def run(self) -> None:
6875

6976
while self._is_running:
7077
self.step()
71-
self.cleanup()
7278

7379
def step(self) -> None:
7480
""" Process a single frame with the pipeline """
7581
self._context.event("step")
7682
if not self._is_paused:
7783
self._dispatch()
7884

79-
def cleanup(self) -> None:
80-
""" Resets all attributes to default configuration """
81-
for stage in self._stages:
82-
stage.close()
83-
84-
self._stages.clear()
85-
self._input_source.close()
86-
self._context.reset()
87-
8885
def event(self, function: Any = None, name: Union[str, None] = None) -> Any:
8986
"""Registers an event handler
9087

tests/test_pipeline.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,6 @@ def test_activate_deactivate():
5454
assert not pipeline.context.is_active
5555

5656

57-
def test_cleanup():
58-
stages = [
59-
mock.MagicMock(),
60-
mock.MagicMock(),
61-
mock.MagicMock(),
62-
]
63-
pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)
64-
65-
pipeline.start()
66-
assert pipeline.is_running
67-
68-
pipeline.stop()
69-
assert not pipeline.is_running
70-
71-
pipeline.cleanup()
72-
assert not pipeline._stages
73-
74-
7557
def test_events():
7658
stages = [
7759
mock.MagicMock(),

0 commit comments

Comments
 (0)