|
231 | 231 | 'PDB sequence database path, used for template search.', |
232 | 232 | ) |
233 | 233 |
|
| 234 | + |
| 235 | +def _num_cpus_for_msa_tools() -> int: |
| 236 | + try: |
| 237 | + # Unfortunately, os.process_cpu_count() is only available in Python 3.13+. |
| 238 | + num_cpus = len(os.sched_getaffinity(0)) |
| 239 | + except AttributeError: |
| 240 | + num_cpus = os.cpu_count() # MacOS doesn't have os.sched_getaffinity(). |
| 241 | + return min(num_cpus if num_cpus is not None else 8, 8) |
| 242 | + |
| 243 | + |
234 | 244 | # Number of CPUs to use for MSA tools. |
235 | 245 | _JACKHMMER_N_CPU = flags.DEFINE_integer( |
236 | 246 | 'jackhmmer_n_cpu', |
237 | | - # Unfortunately, os.process_cpu_count() is only available in Python 3.13+. |
238 | | - min(len(os.sched_getaffinity(0)), 8), |
| 247 | + _num_cpus_for_msa_tools(), |
239 | 248 | 'Number of CPUs to use for Jackhmmer. Defaults to min(cpu_count, 8). Going' |
240 | 249 | ' above 8 CPUs provides very little additional speedup.', |
241 | 250 | lower_bound=0, |
|
250 | 259 | ) |
251 | 260 | _NHMMER_N_CPU = flags.DEFINE_integer( |
252 | 261 | 'nhmmer_n_cpu', |
253 | | - # Unfortunately, os.process_cpu_count() is only available in Python 3.13+. |
254 | | - min(len(os.sched_getaffinity(0)), 8), |
| 262 | + _num_cpus_for_msa_tools(), |
255 | 263 | 'Number of CPUs to use for Nhmmer. Defaults to min(cpu_count, 8). Going' |
256 | 264 | ' above 8 CPUs provides very little additional speedup.', |
257 | 265 | lower_bound=0, |
|
0 commit comments