Added many many debug statements to help debug issue #32
This commit is contained in:
parent
0948c9308a
commit
5672b82f5e
4 changed files with 25 additions and 8 deletions
|
|
@ -99,17 +99,19 @@ app.register_blueprint(plugin_blueprint, url_prefix=uri('/plugin', 'v1'))
|
||||||
task_blueprint = blueprints.task.construct_blueprint(api_microscope)
|
task_blueprint = blueprints.task.construct_blueprint(api_microscope)
|
||||||
app.register_blueprint(task_blueprint, url_prefix=uri('/task', 'v1'))
|
app.register_blueprint(task_blueprint, url_prefix=uri('/task', 'v1'))
|
||||||
|
|
||||||
|
|
||||||
# Automatically clean up microscope at exit
|
# Automatically clean up microscope at exit
|
||||||
def cleanup():
|
def cleanup():
|
||||||
global api_microscope
|
global api_microscope
|
||||||
|
logging.debug("App teardown started...")
|
||||||
# Save config
|
# Save config
|
||||||
api_microscope.rc.save(backup=True)
|
api_microscope.rc.save(backup=True)
|
||||||
# Close down the microscope
|
# Close down the microscope
|
||||||
api_microscope.close()
|
api_microscope.close()
|
||||||
|
logging.debug("App teardown complete.")
|
||||||
|
|
||||||
|
|
||||||
atexit.register(cleanup)
|
atexit.register(cleanup)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0', port="5000", threaded=True, debug=True, use_reloader=False)
|
app.run(host='0.0.0.0', port="5000", threaded=True, debug=True, use_reloader=False)
|
||||||
|
|
|
||||||
|
|
@ -135,12 +135,14 @@ class BaseCamera(object):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the BaseCamera and all attached StreamObjects."""
|
"""Close the BaseCamera and all attached StreamObjects."""
|
||||||
|
logging.info("Closing {}".format(self))
|
||||||
# Close all StreamObjects
|
# Close all StreamObjects
|
||||||
for capture_list in [self.images, self.videos]:
|
for capture_list in [self.images, self.videos]:
|
||||||
for stream_object in capture_list:
|
for stream_object in capture_list:
|
||||||
stream_object.close()
|
stream_object.close()
|
||||||
# Stop worker thread
|
# Stop worker thread
|
||||||
self.stop_worker()
|
self.stop_worker()
|
||||||
|
logging.info("Closed {}".format(self))
|
||||||
|
|
||||||
def wait_for_camera(self, timeout=5):
|
def wait_for_camera(self, timeout=5):
|
||||||
"""Wait for camera object, with 5 second timeout."""
|
"""Wait for camera object, with 5 second timeout."""
|
||||||
|
|
@ -159,10 +161,12 @@ class BaseCamera(object):
|
||||||
|
|
||||||
self.last_access = time.time()
|
self.last_access = time.time()
|
||||||
self.stop = False
|
self.stop = False
|
||||||
|
|
||||||
if self.thread is None:
|
#if self.thread is None:
|
||||||
|
if not self.state['stream_active']:
|
||||||
# start background frame thread
|
# start background frame thread
|
||||||
self.thread = threading.Thread(target=self._thread)
|
self.thread = threading.Thread(target=self._thread)
|
||||||
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
# wait until frames are available
|
# wait until frames are available
|
||||||
|
|
@ -171,7 +175,7 @@ class BaseCamera(object):
|
||||||
if time.time() > timeout_time:
|
if time.time() > timeout_time:
|
||||||
raise TimeoutError("Timeout waiting for frames.")
|
raise TimeoutError("Timeout waiting for frames.")
|
||||||
else:
|
else:
|
||||||
time.sleep(0)
|
time.sleep(0.1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def stop_worker(self, timeout: int = 5) -> bool:
|
def stop_worker(self, timeout: int = 5) -> bool:
|
||||||
|
|
@ -179,12 +183,19 @@ class BaseCamera(object):
|
||||||
logging.debug("Stopping worker thread")
|
logging.debug("Stopping worker thread")
|
||||||
timeout_time = time.time() + timeout
|
timeout_time = time.time() + timeout
|
||||||
|
|
||||||
self.stop = True
|
#if self.thread:
|
||||||
while self.thread:
|
if self.state['stream_active']:
|
||||||
|
self.stop = True
|
||||||
|
self.thread.join() # Wait for stream thread to exit
|
||||||
|
logging.debug("Waiting for stream thread to exit.")
|
||||||
|
|
||||||
|
#while self.thread:
|
||||||
|
while self.state['stream_active']:
|
||||||
if time.time() > timeout_time:
|
if time.time() > timeout_time:
|
||||||
|
logging.debug("Timeout waiting for worker thread close.")
|
||||||
raise TimeoutError("Timeout waiting for worker thread close.")
|
raise TimeoutError("Timeout waiting for worker thread close.")
|
||||||
else:
|
else:
|
||||||
time.sleep(0)
|
time.sleep(0.1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# HANDLE STREAM FRAMES
|
# HANDLE STREAM FRAMES
|
||||||
|
|
@ -387,4 +398,5 @@ class BaseCamera(object):
|
||||||
# Set stream_activate state
|
# Set stream_activate state
|
||||||
self.state['stream_active'] = False
|
self.state['stream_active'] = False
|
||||||
# Reset thread
|
# Reset thread
|
||||||
self.thread = None
|
#self.thread = None
|
||||||
|
logging.debug("Stream thread is None")
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ def clear_tmp():
|
||||||
for f in files:
|
for f in files:
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
logging.debug("Removed {}".format(f))
|
logging.debug("Removed {}".format(f))
|
||||||
|
logging.debug("Cleared {}.".format(TEMP_CAPTURE_PATH))
|
||||||
|
|
||||||
|
|
||||||
def capture_from_dict(capture_dict):
|
def capture_from_dict(capture_dict):
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,12 @@ class Microscope(object):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Shut down the microscope hardware."""
|
"""Shut down the microscope hardware."""
|
||||||
|
logging.info("Closing {}".format(self))
|
||||||
if self.camera:
|
if self.camera:
|
||||||
self.camera.close()
|
self.camera.close()
|
||||||
if self.stage:
|
if self.stage:
|
||||||
self.stage.close()
|
self.stage.close()
|
||||||
|
logging.info("Closed {}".format(self))
|
||||||
|
|
||||||
def attach(self, camera: StreamingCamera, stage: OpenFlexureStage):
|
def attach(self, camera: StreamingCamera, stage: OpenFlexureStage):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue