Skip to content

Commit

Permalink
Bump PyJavaZ and remove pycromanager.logging
Browse files Browse the repository at this point in the history
This removes public API (first introduced in #719) for bypassing
Python's internal logging system by creating and caching a logger
instance in place of using `logging.getLogger("pycromanager")`.

Users of that previous API---i.e., application code authors that want to
globally control logging and users that want to customize Pycromanager's
logging outputs---are encouraged to simply directly use the logging
module to affect these changes instead. See #766 for discussion.
  • Loading branch information
bruno-digitbio committed Jun 7, 2024
1 parent 3bc48f8 commit 945f8f7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 52 deletions.
14 changes: 0 additions & 14 deletions docs/source/apis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,3 @@ Convenience classes for special Java objects

.. autoclass:: Studio
:members:


Logging control
###############

set_logging_instance
====================

.. autofunction:: set_logging_instance

reset_logger_instance
=====================

.. autofunction:: reset_logger_instance
1 change: 0 additions & 1 deletion pycromanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
from pycromanager.core import Core
from pyjavaz import JavaObject, JavaClass, PullSocket, PushSocket
from pycromanager.acquisition.acq_eng_py.main.acq_notification import AcqNotification
from pycromanager.logging import set_logger_instance, reset_logger_instance
from ndtiff import Dataset
from ._version import __version__, version_info
2 changes: 1 addition & 1 deletion pycromanager/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (0, 32, 1)
version_info = (0, 33, 0)
__version__ = ".".join(map(str, version_info))
11 changes: 7 additions & 4 deletions pycromanager/acquisition/java_backend_acquisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The Pycro-manager Acquisiton system
"""
import json
import logging
import warnings
import weakref

Expand All @@ -15,7 +16,7 @@
from pyjavaz import DEFAULT_BRIDGE_PORT as DEFAULT_PORT
from pycromanager.mm_java_classes import ZMQRemoteMMCoreJ, Magellan
from pycromanager.acquisition.java_RAMStorage import JavaRAMDataStorage
import pycromanager.logging as logging

from ndtiff import Dataset
import os.path
import queue
Expand All @@ -25,6 +26,8 @@
from pycromanager.acq_future import AcqNotification, AcquisitionFuture
import json

logger = logging.getLogger(__name__)


### These functions are defined outside the Acquisition class to
# prevent problems with pickling when running them in differnet process
Expand All @@ -36,7 +39,7 @@ def _run_acq_event_source(acquisition, event_port, event_queue, debug=False):
while True:
events = event_queue.get(block=True)
if debug:
logging.main_logger.debug(f"got event(s): {events}")
logger.debug(f"got event(s): {events}")
if events is None:
# Initiate the normal shutdown process
if not acquisition._acq.is_finished():
Expand All @@ -54,7 +57,7 @@ def _run_acq_event_source(acquisition, event_port, event_queue, debug=False):
# maybe consider putting a timeout on the send?
event_socket.send({"events": events if type(events) == list else [events]})
if debug:
logging.main_logger.debug("sent events")
logger.debug("sent events")
except Exception as e:
acquisition.abort(e)
finally:
Expand Down Expand Up @@ -109,7 +112,7 @@ def _run_image_processor(
push_socket = PushSocket(pull_port, debug=debug)
pull_socket = PullSocket(push_port, debug=debug)
if debug:
logging.main_logger.debug("image processing sockets connected")
logger.debug("image processing sockets connected")
sockets_connected_evt.set()

def process_and_sendoff(image_tags_tuple, original_dtype):
Expand Down
32 changes: 17 additions & 15 deletions pycromanager/headless.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import subprocess
import platform
import atexit
Expand All @@ -7,12 +8,13 @@

from pycromanager.acquisition.acq_eng_py.internal.engine import Engine
from pymmcore import CMMCore
import pycromanager.logging as logging
import pymmcore
from pyjavaz import DEFAULT_BRIDGE_PORT, server_terminated

import re

logger = logging.getLogger(__name__)

class TaggedImage:

def __init__(self, tags, pix):
Expand Down Expand Up @@ -94,29 +96,29 @@ def stop_headless(debug=False):
for p in _JAVA_HEADLESS_SUBPROCESSES:
port = p.port
if debug:
logging.main_logger.debug('Stopping headless process with pid {}'.format(p.pid))
logger.debug('Stopping headless process with pid {}'.format(p.pid))
p.terminate()
server_terminated(port)
if debug:
logging.main_logger.debug('Waiting for process with pid {} to terminate'.format(p.pid))
logger.debug('Waiting for process with pid {} to terminate'.format(p.pid))
p.wait() # wait for process to terminate
if debug:
logging.main_logger.debug('Process with pid {} terminated'.format(p.pid))
logger.debug('Process with pid {} terminated'.format(p.pid))
_JAVA_HEADLESS_SUBPROCESSES.clear()
if debug:
logging.main_logger.debug('Stopping {} pymmcore instances'.format(len(_PYMMCORES)))
logger.debug('Stopping {} pymmcore instances'.format(len(_PYMMCORES)))
for c in _PYMMCORES:
if debug:
logging.main_logger.debug('Stopping pymmcore instance')
logger.debug('Stopping pymmcore instance')
c.unloadAllDevices()
if debug:
logging.main_logger.debug('Unloaded all devices')
logger.debug('Unloaded all devices')
Engine.get_instance().shutdown()
if debug:
logging.main_logger.debug('Engine shut down')
logger.debug('Engine shut down')
_PYMMCORES.clear()
if debug:
logging.main_logger.debug('Headless stopped')
logger.debug('Headless stopped')

# make sure any Java processes are cleaned up when Python exits
atexit.register(stop_headless)
Expand Down Expand Up @@ -177,13 +179,13 @@ def start_headless(
else:
java_loc = "java"
if debug:
logging.main_logger.debug(f'Java location: {java_loc}')
logger.debug(f'Java location: {java_loc}')
#print classpath
logging.main_logger.debug(f'Classpath: {classpath}')
logger.debug(f'Classpath: {classpath}')
# print stuff in the classpath directory
logging.main_logger.debug('Contents of classpath directory:')
logger.debug('Contents of classpath directory:')
for f in os.listdir(classpath.split('*')[0]):
logging.main_logger.debug(f)
logger.debug(f)

# This starts Java process and instantiates essential objects (core,
# acquisition engine, ZMQServer)
Expand Down Expand Up @@ -215,12 +217,12 @@ def start_headless(
if not started:
raise Exception('Error starting headless mode')
if debug:
logging.main_logger.debug('Headless mode started')
logger.debug('Headless mode started')
def loggerFunction():
while process in _JAVA_HEADLESS_SUBPROCESSES:
line = process.stdout.readline().decode('utf-8')
if line.strip() != '':
logging.main_logger.debug(line)
logger.debug(line)
threading.Thread(target=loggerFunction).start()


16 changes: 0 additions & 16 deletions pycromanager/logging.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ndtiff>=2.3.0
docstring-inheritance
pymmcore
sortedcontainers
pyjavaz==1.1.0
pyjavaz==1.1.1

0 comments on commit 945f8f7

Please sign in to comment.