diff --git a/src/stopit/__init__.py b/src/stopit/__init__.py index 6ca0180..bbf7068 100644 --- a/src/stopit/__init__.py +++ b/src/stopit/__init__.py @@ -7,18 +7,25 @@ Public resources from ``stopit`` """ -import pkg_resources - from .utils import LOG, TimeoutException -from .threadstop import ThreadingTimeout, async_raise, threading_timeoutable -from .signalstop import SignalTimeout, signal_timeoutable -# PEP 396 style version marker try: - __version__ = pkg_resources.get_distribution(__name__).version -except: - LOG.warning("Could not get the package version from pkg_resources") - __version__ = 'unknown' + from importlib.metadata import version + __version__ = version(__name__) +except Exception: + # pkg_resources is deprecated as of Python 3.12 and no longer available for + # import by default. + try: + import pkg_resources + except Exception: + LOG.warning( + "Could not get the package version from importlib or pkg_resources") + __version__ = 'unknown' + else: + __version__ = pkg_resources.get_distribution(__name__).version + +from .threadstop import ThreadingTimeout, async_raise, threading_timeoutable +from .signalstop import SignalTimeout, signal_timeoutable __all__ = ( 'ThreadingTimeout', 'async_raise', 'threading_timeoutable',