U
    襡c'                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZmZmZmZmZmZmZ ejejd  ddZdadd Zdd Ze jdd
dZdS )    N)ObjectIDObjectNotAvailablePlasmaBufferPlasmaClientconnectPlasmaObjectExistsPlasmaObjectNotFoundPlasmaStoreFull
tensorflowplasma_op.soc                  C   s   dd l } | tad S )Nr   )r
   load_op_libraryTF_PLASMA_OP_PATHtf_plasma_op)tf r   2/tmp/pip-unpacked-wheel-qoi2rb4q/pyarrow/plasma.pyload_plasma_tensorflow_op/   s    r   c                  C   s.  zdd l } td| j  W n tk
r.   Y nX td tjtjt}tj	|dd}tj	|dd}| j
 }tjdkrdd	g| }d
ddd|d|ddt  g	}|dd t D 7 }|ddddg7 }||7 }|| j
 7 }|dg7 }| j r|dg7 }tdt|  t| | tad S )Nr   zTensorFlow version: z!Compiling Plasma TensorFlow Op...r
   zplasma_op.ccr   darwinz
-undefinedZdynamic_lookupzg++z
-std=c++17z-gz-sharedz-oz-DNDEBUGz-Ic                 S   s   g | ]}d | qS )z-Lr   ).0dirr   r   r   
<listcomp>F   s     z.build_plasma_tensorflow_op.<locals>.<listcomp>z-lplasmaz-larrow_pythonz-larrowz-fPICz-O2z-DGOOGLE_CUDAzRunning command )r
   print__version__ImportErrorospathdirnamerealpath__file__join	sysconfigZget_compile_flagssysplatformpaZget_includeZget_library_dirsZget_link_flagstestZis_built_with_cudastr
subprocess
check_callr   r   r   )r   Zdir_pathZcc_pathZso_pathZ	tf_cflagscmdr   r   r   build_plasma_tensorflow_op5   s8    


   



r)   Fc              	   c   s  t dt |r|rtdtjdd}z6t
j|d}t
jtjd d}	t
j|	slt
jtjd	d}	|	d
|dt| g}
|r|
d|g7 }
|r|
dg7 }
|dk	r|
d|g7 }
d}d}|rddddddg|
 }
tj|
||d}td nH|rddg|
 }
tj|
||d}td ntj|
||d}td | }|dk	rTtd|f ||fV  W 5 | dkrx|  t	| X dS )a  
    DEPRECATED: Start a plasma store process.

    .. deprecated:: 10.0.0
       Plasma is deprecated since Arrow 10.0.0. It will be removed
       in 12.0.0 or so.

    Parameters
    ----------
    plasma_store_memory : int
        Capacity of the plasma store in bytes.
    use_valgrind : bool
        True if the plasma store should be started inside of valgrind. If this
        is True, use_profiler must be False.
    use_profiler : bool
        True if the plasma store should be started inside a profiler. If this
        is True, use_valgrind must be False.
    plasma_directory : str
        Directory where plasma memory mapped files will be stored.
    use_hugepages : bool
        True if the plasma store should use huge pages.
    external_store : str
        External store to use for evicted objects.

    Returns
    -------
    result : (str, subprocess.Popen)
        A tuple of the name of the plasma store socket and the process ID of
        the plasma store process.
    zLPlasma is deprecated since Arrow 10.0.0. It will be removed in 12.0.0 or so.z2Cannot use valgrind and profiler at the same time.ztest_plasma-)prefixNzplasma.sockr   zplasma-store-serverbinz-sz-mz-dz-hz-eZvalgrindz--track-origins=yesz--leak-check=fullz--show-leak-kinds=allz!--leak-check-heuristics=stdstringz--error-exitcode=1)stdoutstderrg      ?z--tool=callgrindg?z-plasma_store exited unexpectedly with code %d)warningswarnDeprecationWarning	Exceptiontempfilemkdtemppollkillshutilrmtreer   r   r   r#   __path__existsr!   r*   r%   r&   PopentimesleepRuntimeError)Zplasma_store_memoryZuse_valgrindZuse_profilerZplasma_directoryZuse_hugepagesZexternal_storeZtmpdirprocZplasma_store_nameZplasma_store_executablecommandZstdout_fileZstderr_filercr   r   r   start_plasma_storeR   s    #     


rA   )FFNFN)
contextlibr   Zpyarrowr#   r6   r&   r!   r2   r;   r.   Zpyarrow._plasmar   r   r   r   r   r   r   r	   r   r   r8   r   r   r   r)   contextmanagerrA   r   r   r   r   <module>   s(   (       