File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,9 +26,7 @@ def __init__(
2626 self .__hostname = str (hostname )
2727 self .__port = port
2828
29- self .__thread = Thread (target = self .retriever )
30- self .__thread .daemon = True
31-
29+ self .__thread = None
3230 self .last_frame = None
3331 self .alive = False
3432
@@ -44,6 +42,8 @@ def start(self):
4442 """
4543 if not self .alive :
4644 self .alive = True
45+ self .__thread = Thread (target = self .retriever )
46+ self .__thread .daemon = True
4747 self .__thread .start ()
4848 return True
4949 else :
@@ -54,7 +54,9 @@ def stop(self):
5454 Stop the camera client
5555 """
5656 self .alive = False
57- self .__thread .join ()
57+ if self .__thread is not None :
58+ self .__thread .join ()
59+ self .__thread = None
5860
5961 def get_frame (self ):
6062 if self .last_frame is None :
Original file line number Diff line number Diff line change 1+ from unittest .mock import patch
2+
3+ from bambulabs_api .camera_client import PrinterCamera
4+
5+
6+ def test_camera_is_reusable ():
7+ camera = PrinterCamera ('1.2.3.4' , 'fake_code' )
8+
9+ # Mock the retriever method so it doesn't do any network I/O.
10+ with patch .object (camera , 'retriever' , return_value = None ):
11+ # First cycle
12+ camera .start ()
13+ camera .stop ()
14+
15+ # Second cycle
16+ camera .start () # This was failing before.
17+ camera .stop ()
You can’t perform that action at this time.
0 commit comments