MCPcopy Index your code
hub / github.com/python/cpython / DupHandle

Class DupHandle

Lib/multiprocessing/reduction.py:104–135  ·  view source on GitHub ↗

Picklable wrapper for a handle.

Source from the content-addressed store, hash-verified

102 return conn.recv().detach()
103
104 class DupHandle(object):
105 '''Picklable wrapper for a handle.'''
106 def __init__(self, handle, access, pid=None):
107 if pid is None:
108 # We just duplicate the handle in the current process and
109 # let the receiving process steal the handle.
110 pid = os.getpid()
111 proc = _winapi.OpenProcess(_winapi.PROCESS_DUP_HANDLE, False, pid)
112 try:
113 self._handle = _winapi.DuplicateHandle(
114 _winapi.GetCurrentProcess(),
115 handle, proc, access, False, 0)
116 finally:
117 _winapi.CloseHandle(proc)
118 self._access = access
119 self._pid = pid
120
121 def detach(self):
122 '''Get the handle. This should only be called once.'''
123 # retrieve handle from process which currently owns it
124 if self._pid == os.getpid():
125 # The handle has already been duplicated for this process.
126 return self._handle
127 # We must steal the handle from the process whose pid is self._pid.
128 proc = _winapi.OpenProcess(_winapi.PROCESS_DUP_HANDLE, False,
129 self._pid)
130 try:
131 return _winapi.DuplicateHandle(
132 proc, self._handle, _winapi.GetCurrentProcess(),
133 self._access, False, _winapi.DUPLICATE_CLOSE_SOURCE)
134 finally:
135 _winapi.CloseHandle(proc)
136
137else:
138 # Unix

Callers 1

send_handleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…