Get the handle. This should only be called once.
(self)
| 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 | |
| 137 | else: |
| 138 | # Unix |
no outgoing calls
no test coverage detected