| 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.''' |