U e5d¥!ã@sÔddlZddlZddlZddlZddlZddlmZddlmZdddgZe edƒZ ej ej fZ d d d „iZejd kršddlZddlZe ejejd œ¡Gdd„deƒZeƒZejZejZejZejZdd„ZdS)éNé)Úspawn)ÚutilÚensure_runningÚregisterÚ unregisterÚpthread_sigmaskZnoopcCsdS©N©r r r ú8/usr/lib64/python3.8/multiprocessing/resource_tracker.pyÚ!ór Úposix)Z semaphoreZ shared_memoryc@sLeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)ÚResourceTrackercCst ¡|_d|_d|_dSr )Ú threadingZLockÚ_lockÚ_fdÚ_pid©Úselfr r r Ú__init__0s zResourceTracker.__init__c CsT|jD|jdkr W5QR£dSt |j¡d|_t |jd¡d|_W5QRXdS)Nr)rrÚosÚcloseÚwaitpidrrr r r Ú_stop5s  zResourceTracker._stopcCs| ¡|jSr )rrrr r r ÚgetfdBszResourceTracker.getfdc Cst|jb|jdk r~| ¡r*W5QR£dSt |j¡z|jdk rPt |jd¡Wntk rfYnXd|_d|_t  d¡g}z|  t j   ¡¡Wntk rªYnXd}t ¡\}}zœzr|  |¡t ¡}|gt ¡}|d||g7}z&trt tjt¡t |||¡}W5tr,t tjt¡XWnt |¡‚YnX||_||_W5t |¡XW5QRXdS)z¬Make sure that resource tracker process is running. This can be run from any process. Usually a child process will use the resource created by its parent.NrzUresource_tracker: process died unexpectedly, relaunching. Some resources might leak.z:from multiprocessing.resource_tracker import main;main(%d)z-c)rrÚ _check_aliverrrrÚChildProcessErrorÚwarningsÚwarnÚappendÚsysÚstderrÚfilenoÚ ExceptionÚpiperZget_executablerZ_args_from_interpreter_flagsÚ _HAVE_SIGMASKÚsignalrÚ SIG_UNBLOCKÚ_IGNORED_SIGNALSÚ SIG_BLOCKZspawnv_passfds)rZ fds_to_passÚcmdÚrÚwZexeÚargsÚpidr r r rFsJ         zResourceTracker.ensure_runningcCs2zt |jd¡Wntk r(YdSXdSdS)z;Check that the pipe has not been closed by sending a probe.s PROBE:0:noop FTN)rÚwriterÚOSErrorrr r r r†s zResourceTracker._check_alivecCs| d||¡dS)z0Register name of resource with resource tracker.ÚREGISTERN©Ú_send©rÚnameÚrtyper r r r‘szResourceTracker.registercCs| d||¡dS)z2Unregister name of resource with resource tracker.Ú UNREGISTERNr3r5r r r r•szResourceTracker.unregistercCsb| ¡d |||¡ d¡}t|ƒdkr0tdƒ‚t |j|¡}|t|ƒks^td |t|ƒ¡ƒ‚dS)Nz {0}:{1}:{2} Úasciiiz name too longznbytes {0:n} but len(msg) {1:n}) rÚformatÚencodeÚlenÚ ValueErrorrr0rÚAssertionError)rr+r6r7ÚmsgÚnbytesr r r r4™s ÿzResourceTracker._sendN) Ú__name__Ú __module__Ú __qualname__rrrrrrrr4r r r r r.s @ rc Cst tjtj¡t tjtj¡tr2t tjt¡tj tj fD]&}z |  ¡Wq>t k rbYq>Xq>dd„t  ¡Dƒ}zìt|dƒØ}|D]Ì}z| ¡ d¡ d¡\}}}t  |d¡} | dkrÒtd |›d |›ƒ‚|d krê|| |¡n2|d kr|| |¡n|d krn td|ƒ‚WqŠt k rTztjt ¡ŽWn YnXYqŠXqŠW5QRXW5| ¡D]ž\}}|r®zt dt|ƒ|f¡Wnt k r¬YnX|D]V}zLzt ||ƒWn6t k rþ}zt d||f¡W5d}~XYnXW5Xq²qnXdS)zRun resource tracker.cSsi|] }|tƒ“qSr )Úset)Ú.0r7r r r Ú ¹szmain..zQresource_tracker: There appear to be %d leaked %s objects to clean up at shutdownzresource_tracker: %r: %sNÚrbr9ú:zCannot register z. for automatic cleanup: unknown resource type r2r8ZPROBEzunrecognized command %r)r'ÚSIGINTÚSIG_IGNÚSIGTERMr&rr(r)r!ÚstdinÚstdoutrr$Ú_CLEANUP_FUNCSÚkeysÚitemsrrr<ÚopenÚstripÚdecodeÚsplitÚgetr=ÚaddÚremoveÚ RuntimeErrorÚ excepthookÚexc_info) ÚfdÚfÚcacher7Z rtype_cacher6ÚeÚliner+Z cleanup_funcr r r Úmain«s^   ÿ   þ (r`)rr'r!rrÚrrÚ__all__Úhasattrr&rIrKr)rNr6Z_multiprocessingZ _posixshmemÚupdateZ sem_unlinkZ shm_unlinkÚobjectrZ_resource_trackerrrrrr`r r r r Ús4     ÿ þw