U
    /e[                     @  sJ   d dl mZ d dlZd dlZd dlZdZeeZddddZ	e	 Z
dS )    )annotationsN)memory_limitMEMORY_LIMITint)returnc               
   C  s   t  j} tjdkrd}dD ]T}z:t|}t| }W 5 Q R X |dkrX|}t| |} W q t	k
rn   Y qX q|rt
d| tjdkrzDddl}||jd }d|  k r| k rn nt
d| |} W n ttfk
r   Y nX | S )	zGet the memory limit (in bytes) for this system.

    Takes the minimum value from the following locations:

    - Total system host memory
    - Cgroups limit (if set)
    - RSS rlimit (if set)
    linuxN)z+/sys/fs/cgroup/memory/memory.limit_in_bytesz0/sys/fs/cgroup/memory/memory.soft_limit_in_bytesz/sys/fs/cgroup/memory.maxz/sys/fs/cgroup/memory.highr   z?Setting system memory limit based on cgroup value defined in %swin32   z0Limiting system memory based on RLIMIT_RSS to %s)psutilZvirtual_memorytotalsysplatformopenr   readmin	ExceptionloggerdebugresourceZ	getrlimitZ
RLIMIT_RSSImportErrorOSError)limitZ	path_usedpathfZcgroups_limitr   Z
hard_limit r   6/tmp/pip-unpacked-wheel-g426oqom/distributed/system.pyr      s<    	



 r   )
__future__r   loggingr   r
   __all__	getLogger__name__r   r   r   r   r   r   r   <module>   s   
4