Viewing File: /opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/resource_sharer.cpython-35.opt-1.pyc



Yf@sddlZddlZddlZddlZddlZddlmZddlmZddlmZdgZ	ej
dkre	dg7Z	Gd	ddeZn#e	d
g7Z	Gdd
d
eZ
Gdd
d
eZeZejZdS)N)process)	reduction)utilstopwin32	DupSocketc@s.eZdZdZddZddZdS)rzPicklable wrapper for a socket.cs:|jfdd}tj|j|_dS)Ncs j|}|j|dS)N)shareZ
send_bytes)connpidr	)new_sockD/opt/alt/python35/lib64/python3.5/multiprocessing/resource_sharer.pysendsz DupSocket.__init__.<locals>.send)dup_resource_sharerregisterclose_id)selfZsockrr
)rr__init__szDupSocket.__init__c	Cs9tj|j }|j}tj|SWdQRXdS)z1Get the socket.  This should only be called once.N)rget_connectionrZ
recv_bytessocketZ	fromshare)rr
r	r
r
rdetach$szDupSocket.detachN)__name__
__module____qualname____doc__rrr
r
r
rrsDupFdc@s.eZdZdZddZddZdS)rz-Wrapper for fd which can be used at any time.csLtj|fdd}fdd}tj|||_dS)Ncstj||dS)N)rZsend_handle)r
r)new_fdr
rr1szDupFd.__init__.<locals>.sendcstjdS)N)osrr
)rr
rr3szDupFd.__init__.<locals>.close)r rrrr)rfdrrr
)rrr/szDupFd.__init__c	Cs-tj|j}tj|SWdQRXdS)z-Get the fd.  This should only be called once.N)rrrrZrecv_handle)rr
r
r
rr7szDupFd.detachN)rrrrrrr
r
r
rr-sc@sseZdZdZddZddZeddZdd	d
ZddZ	d
dZ
ddZdS)_ResourceSharerz-Manager for resouces using background thread.cCs\d|_i|_g|_tj|_d|_d|_d|_t	j
|tjdS)Nr)
_key_cache
_old_locks	threadingLock_lock	_listener_address_threadrZregister_after_forkr"
_afterfork)rr
r
rr?s						z_ResourceSharer.__init__c
Csc|jS|jdkr#|j|jd7_||f|j|j<|j|jfSWdQRXdS)z+Register resource, returning an identifier.Nr)r(r*_startr#r$)rrrr
r
rrIs

z_ResourceSharer.registercCsTddlm}|\}}||dtjj}|j|tjf|S)z<Return connection from which to receive identified resource.r)Clientauthkey)
connectionr.rcurrent_processr/rr getpid)Zidentr.addresskeycr
r
rrRs
z_ResourceSharer.get_connectionNcCsddlm}|j|jdk	r||jdtjj}|jd|j|j	j
||j	jrtj
d|jjd|_	d|_d|_x*|jjD]\}\}}|qW|jjWdQRXdS)z:Stop the background thread and clear registered resources.r)r.Nr/z._ResourceSharer thread did not stop when asked)r0r.r(r*rr1r/rrr+joinZis_aliverZsub_warningr)r$itemsclear)rZtimeoutr.r5r4rrr
r
rr[s"




			"z_ResourceSharer.stopcCsx*|jjD]\}\}}|qW|jj|jj|jtj|_|jdk	rx|jj	d|_d|_
d|_dS)N)r$r7r8r%appendr(r&r'r)rr*r+)rr4rrr
r
rr,ps"

		z_ResourceSharer._afterforkcCs|ddlm}tjd|dtjj|_|jj|_	t
jd|j}d|_
|j||_dS)Nr)Listenerz0starting listener and thread for sending handlesr/targetT)r0r:rdebugrr1r/r)r3r*r&ZThread_serveZdaemonstartr+)rr:tr
r
rr-~s
	
z_ResourceSharer._startcCsttdr.tjtjtdtjxyv|jj`}|j}|dkr_P|\}}|j	j
|\}}z|||Wd|XWdQRXWq1tjst
jt
jYq1Xq1WdS)Npthread_sigmaskr)hasattrsignalr@	SIG_BLOCKrangeNSIGr)ZacceptZrecvr$poprZ
is_exitingsys
excepthookexc_info)rr
msgr4Zdestination_pidrrr
r
rr=s z_ResourceSharer._serve)rrrrrrstaticmethodrrr,r-r=r
r
r
rr"=s
		r")r rBrrGr&rrr__all__platformobjectrrr"rrr
r
r
r<module>s 	

`	
Back to Directory File Manager