o w[e #@sddlZddlZddlZddlZddlZddlmZddlmZgdZe edZ ej ej fZ ddd iZejd krWddlZddlZe ed rOed ejied ejiGdddeZeZejZejZejZejZddZdS)N)spawn)util)ensure_runningregister unregisterpthread_sigmasknoopcCsdSNr r r 7/usr/lib/python3.10/multiprocessing/resource_tracker.py!sr posix sem_unlink semaphore shared_memoryc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)ResourceTrackercCst|_d|_d|_dSr ) threadingLock_lock_fd_pidselfr r r __init__8s  zResourceTracker.__init__cCsn|j*|jdur WddSt|jd|_t|jdd|_WddS1s0wYdS)Nr)rrosclosewaitpidrrr r r _stop=s  "zResourceTracker._stopcCs||jSr )rrrr r r getfdJszResourceTracker.getfdc Cs|j|jdur?|r WddSt|jz|jdur)t|jdWn ty3Ynwd|_d|_t dg}z | t j Wn tyTYnwd}t\}}zXzA| |t}|gt}|d||g7}ztrttjtt|||}Wtrttjtn trttjtwwWn t|||_||_Wt|nt|wWddS1swYdS)zMake 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_aliverrrrChildProcessErrorwarningswarnappendsysstderrfileno Exceptionpiperget_executabler_args_from_interpreter_flags _HAVE_SIGMASKsignalr SIG_BLOCK_IGNORED_SIGNALSspawnv_passfds SIG_UNBLOCK)r fds_to_passcmdrwexeargspidr r r rNs^         "zResourceTracker.ensure_runningcCs*z t|jdWdStyYdSw)z;Check that the pipe has not been closed by sending a probe.s PROBE:0:noop FT)rwriterOSErrorrr r r r s  zResourceTracker._check_alivecC|d||dS)z0Register name of resource with resource tracker.REGISTERN_sendrnamertyper r r rzResourceTracker.registercCr;)z2Unregister name of resource with resource tracker. UNREGISTERNr=r?r r r rrBzResourceTracker.unregistercCsb|d|||d}t|dkrtdt|j|}|t|ks/Jd|t|dS)Nz {0}:{1}:{2} asciiiz msg too longznbytes {0:n} but len(msg) {1:n})rformatencodelen ValueErrorrr9r)rr3r@rAmsgnbytesr r r r>s  zResourceTracker._sendN) __name__ __module__ __qualname__rrrrr rrr>r r r r r6s @  rc Csttjtjttjtjtrttjttj tj fD]}z| Wqt y0Yqwddt D}zt|dj}|D]_}zF|dd\}}}t |d}|durgtd|d||d krs|||n|d kr|||n |d krntd |WqCt yz tjtWnYYqCwWdn1swYW|D]I\}}|rz td t||fWn t yYnw|D])}z&zt ||Wnt y} ztd|| fWYd} ~ nd} ~ wwWqwqdS|D]N\}}|r&z td t||fWn t y%Ynw|D]+}z(zt ||Wnt yO} ztd|| fWYd} ~ nd} ~ wwWq(wqw)zRun resource tracker.cSsi|]}|tqSr )set).0rAr r r szmain..rbrD:NzCannot register z. for automatic cleanup: unknown resource type r<rCPROBEzunrecognized command %rzQresource_tracker: There appear to be %d leaked %s objects to clean up at shutdownzresource_tracker: %r: %s)r-SIGINTSIG_IGNSIGTERMr,rr1r/r%stdinstdoutrr(_CLEANUP_FUNCSkeysopenstripdecodesplitgetrHaddremove RuntimeError excepthookexc_infoitemsr"r#rG) fdfcacheliner3r@rA cleanup_func rtype_cacheer r r mains          rm)rr-r%rr"rr__all__hasattrr,rTrVr/rYr@_multiprocessing _posixshmemupdater shm_unlinkobjectr_resource_trackerrrrrrmr r r r s:      w