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 42
42
if os .name == 'nt' :
43
43
_dll_path = os .getenv ('OPENSLIDE_PATH' )
44
44
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
46
46
import openslide
47
47
else :
48
48
import openslide
Original file line number Diff line number Diff line change 42
42
if os .name == 'nt' :
43
43
_dll_path = os .getenv ('OPENSLIDE_PATH' )
44
44
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
46
46
import openslide
47
47
else :
48
48
import openslide
Original file line number Diff line number Diff line change 48
48
if os .name == 'nt' :
49
49
_dll_path = os .getenv ('OPENSLIDE_PATH' )
50
50
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
52
52
import openslide
53
53
else :
54
54
import openslide
@@ -382,6 +382,19 @@ def _shutdown(self) -> None:
382
382
383
383
384
384
if __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
+
385
398
parser = ArgumentParser (usage = '%(prog)s [options] <SLIDE>' )
386
399
parser .add_argument (
387
400
'-B' ,
@@ -433,8 +446,8 @@ def _shutdown(self) -> None:
433
446
metavar = 'COUNT' ,
434
447
dest = 'workers' ,
435
448
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 } ]' ,
438
451
)
439
452
parser .add_argument (
440
453
'-o' ,
Original file line number Diff line number Diff line change 30
30
# environment.
31
31
_dll_path = os .getenv ('OPENSLIDE_PATH' )
32
32
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
34
34
import openslide # noqa: F401 module-imported-but-unused
35
35
36
36
You can’t perform that action at this time.
0 commit comments