diff --git a/examples/deepzoom/deepzoom_tile.py b/examples/deepzoom/deepzoom_tile.py index 614b032..6f52324 100755 --- a/examples/deepzoom/deepzoom_tile.py +++ b/examples/deepzoom/deepzoom_tile.py @@ -382,6 +382,19 @@ def _shutdown(self) -> None: if __name__ == '__main__': + try: + # Python 3.13+ + available_cpus = os.process_cpu_count() # type: ignore[attr-defined] + except AttributeError: + try: + # Linux + available_cpus = len( + os.sched_getaffinity(0) # type: ignore[attr-defined,unused-ignore] + ) + except AttributeError: + # default + available_cpus = 4 + parser = ArgumentParser(usage='%(prog)s [options] ') parser.add_argument( '-B', @@ -433,8 +446,8 @@ def _shutdown(self) -> None: metavar='COUNT', dest='workers', type=int, - default=4, - help='number of worker processes to start [4]', + default=available_cpus, + help=f'number of worker processes to start [{available_cpus}]', ) parser.add_argument( '-o',