Skip to content

Commit

Permalink
better error handling (but still havent fixed test)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypinkard committed Jun 14, 2024
1 parent 6607cd0 commit 7ce58ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pycromanager/acquisition/RAMStorage_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def read_image(self, channel=None, z=None, time=None, position=None, row=None, c
if key not in self._index_keys:
return None
java_hashmap = JavaObject('java.util.HashMap')
# raise Exception
for k, v in axes.items():
java_hashmap.put(k, v)
tagged_image = self._java_RAM_data_storage.get_image(java_hashmap)
print('java ram storage class:', str(self._java_RAM_data_storage))
print('tagged image: ', str(tagged_image))
pixels = tagged_image.pix
metadata = tagged_image.tags
return pixels.reshape(metadata['Height'], metadata['Width'])
Expand Down
28 changes: 17 additions & 11 deletions pycromanager/acquisition/java_backend_acquisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def _notification_handler_fn(acquisition, notification_push_port, connected_even
monitor_socket = PullSocket(notification_push_port)
connected_event.set()

try:
events_finished = False
data_sink_finished = False
while True:
events_finished = False
data_sink_finished = False
while True:
try:
message = monitor_socket.receive()
notification = AcqNotification.from_json(message)

Expand Down Expand Up @@ -226,11 +226,12 @@ def _notification_handler_fn(acquisition, notification_push_port, connected_even
if events_finished and data_sink_finished:
break

except Exception as e:
traceback.print_exc()
acquisition.abort(e)
finally:
monitor_socket.close()
except Exception as e:
traceback.print_exc()
acquisition.abort(e)
continue # perform an orderly shutdown

monitor_socket.close()


class JavaBackendAcquisition(Acquisition, metaclass=NumpyDocstringInheritanceMeta):
Expand Down Expand Up @@ -319,6 +320,7 @@ def __init__(
# while the acquisition is still running, and (optionally )so that a image_saved_fn can be called
# when images are written to disk/RAM storage
storage_java_class = data_sink.get_storage()
print(storage_java_class)
summary_metadata = storage_java_class.get_summary_metadata()
if directory is not None:
# NDTiff dataset saved to disk on Java side
Expand Down Expand Up @@ -380,8 +382,12 @@ def await_completion(self):
self._remote_notification_handler = None
self._acq_notification_dispatcher_thread.join()

self._acq = None
self._finished = True
try:
# one final check for exceptions for stuff that may have happened during shutdown
self._check_for_exceptions()
finally:
self._acq = None
self._finished = True


def get_viewer(self):
Expand Down
8 changes: 6 additions & 2 deletions pycromanager/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def install_mm():



@pytest.fixture(scope="session", params=['save_to_disk', 'RAM'])
# @pytest.fixture(scope="session", params=['save_to_disk', 'RAM'])
@pytest.fixture(scope="session", params=['RAM'])

def setup_data_folder(request):
if request.param != 'save_to_disk':
yield None
Expand All @@ -145,7 +147,9 @@ def setup_data_folder(request):
shutil.rmtree(data_folder_path)


@pytest.fixture(scope="session", params=['python_backend', 'java_backend'])
# @pytest.fixture(scope="session", params=['python_backend', 'java_backend'])
@pytest.fixture(scope="session", params=['java_backend'])

def launch_mm_headless(request, install_mm):
python_backend = request.param == 'python_backend'
mm_install_dir = install_mm
Expand Down
1 change: 1 addition & 0 deletions pycromanager/test/test_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_empty_mda_acq(launch_mm_headless, setup_data_folder):
with Acquisition(setup_data_folder, 'acq', show_display=False) as acq:
acq.acquire(events)


dataset = acq.get_dataset()
try:
assert dataset.axes == {}
Expand Down

0 comments on commit 7ce58ad

Please sign in to comment.