File tree Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 4242if os .name == 'nt' :
4343 _dll_path = os .getenv ('OPENSLIDE_PATH' )
4444 if _dll_path is not None :
45- with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined]
45+ with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined,unused-ignore] # noqa: E501
4646 import openslide
4747 else :
4848 import openslide
Original file line number Diff line number Diff line change 4242if os .name == 'nt' :
4343 _dll_path = os .getenv ('OPENSLIDE_PATH' )
4444 if _dll_path is not None :
45- with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined]
45+ with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined,unused-ignore] # noqa: E501
4646 import openslide
4747 else :
4848 import openslide
Original file line number Diff line number Diff line change 4848if os .name == 'nt' :
4949 _dll_path = os .getenv ('OPENSLIDE_PATH' )
5050 if _dll_path is not None :
51- with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined]
51+ with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined,unused-ignore] # noqa: E501
5252 import openslide
5353 else :
5454 import openslide
@@ -382,6 +382,19 @@ def _shutdown(self) -> None:
382382
383383
384384if __name__ == '__main__' :
385+ try :
386+ # Python 3.13+
387+ available_cpus = os .process_cpu_count () # type: ignore[attr-defined]
388+ except AttributeError :
389+ try :
390+ # Linux
391+ available_cpus = len (
392+ os .sched_getaffinity (0 ) # type: ignore[attr-defined,unused-ignore]
393+ )
394+ except AttributeError :
395+ # default
396+ available_cpus = 4
397+
385398 parser = ArgumentParser (usage = '%(prog)s [options] <SLIDE>' )
386399 parser .add_argument (
387400 '-B' ,
@@ -433,8 +446,8 @@ def _shutdown(self) -> None:
433446 metavar = 'COUNT' ,
434447 dest = 'workers' ,
435448 type = int ,
436- default = 4 ,
437- help = 'number of worker processes to start [4 ]' ,
449+ default = available_cpus ,
450+ help = f 'number of worker processes to start [{ available_cpus } ]' ,
438451 )
439452 parser .add_argument (
440453 '-o' ,
Original file line number Diff line number Diff line change 3030 # environment.
3131 _dll_path = os .getenv ('OPENSLIDE_PATH' )
3232 if _dll_path is not None :
33- with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined]
33+ with os .add_dll_directory (_dll_path ): # type: ignore[attr-defined,unused-ignore] # noqa: E501
3434 import openslide # noqa: F401 module-imported-but-unused
3535
3636
You can’t perform that action at this time.
0 commit comments