o
    Nrf)                     @  sf   d dl mZ d dlZd dlZd dlZzd dlZW n ey#   dZY nw dZdd Zdd Z	e	 Z
dS )    )annotationsN)	cpu_count	CPU_COUNTc               	   C  sV  dD ]J} z?t d|  }t| }W d    n1 sw   Y  t d|  }t| }W d    n1 s8w   Y  ||fW   S  tyL   Y qw zSt d}|  dd }W d    n1 shw   Y  |dsw| d}t d| }tt| d	\}}||fW  d    W S 1 sw   Y  W d
S  ty   Y d
S w )N)zcpuacct,cpuzcpu,cpuacctz"/sys/fs/cgroup/%s/cpu.cfs_quota_usz#/sys/fs/cgroup/%s/cpu.cfs_period_usz/proc/self/cgroup:/z/sys/fs/cgroup%scpu.max )NN)openintread	Exceptionstripsplitendswithmap)dirnamefquotaperiodZ
group_path r   T/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/dask/system.py_try_extract_cgroup_cpu_quota   s6   


$r   c                  C  s   t  } tdur%ztt  }|dkrt| |} W n	 ty$   Y nw tj	dkrGt
 \}}|durG|durGt|| }|dkrGt| |} | S )zGet the available CPU count for this system.

    Takes the minimum value from the following locations:

    - Total system cpus available on the host.
    - CPU Affinity (if set)
    - Cgroups limit (if set)
    Nr   linux)osr   psutillenProcessZcpu_affinityminr   sysplatformr   mathceil)countZaffinity_countr   r   Zcgroups_countr   r   r   r   ,   s"   	



r   )
__future__r   r    r   r   r   ImportError__all__r   r   r   r   r   r   r   <module>   s    
 