MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / Handle

Class Handle

pydevd_attach_to_process/winappdbg/win32/kernel32.py:572–767  ·  view source on GitHub ↗

Encapsulates Win32 handles to avoid leaking them. @type inherit: bool @ivar inherit: C{True} if the handle is to be inherited by child processes, C{False} otherwise. @type protectFromClose: bool @ivar protectFromClose: Set to C{True} to prevent the handle from being

Source from the content-addressed store, hash-verified

570
571
572class Handle(object):
573 """
574 Encapsulates Win32 handles to avoid leaking them.
575
576 @type inherit: bool
577 @ivar inherit: C{True} if the handle is to be inherited by child processes,
578 C{False} otherwise.
579
580 @type protectFromClose: bool
581 @ivar protectFromClose: Set to C{True} to prevent the handle from being
582 closed. Must be set to C{False} before you're done using the handle,
583 or it will be left open until the debugger exits. Use with care!
584
585 @see:
586 L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
587 """
588
589 # XXX DEBUG
590 # When this private flag is True each Handle will print a message to
591 # standard output when it's created and destroyed. This is useful for
592 # detecting handle leaks within WinAppDbg itself.
593 __bLeakDetection = False
594
595 def __init__(self, aHandle=None, bOwnership=True):
596 """
597 @type aHandle: int
598 @param aHandle: Win32 handle value.
599
600 @type bOwnership: bool
601 @param bOwnership:
602 C{True} if we own the handle and we need to close it.
603 C{False} if someone else will be calling L{CloseHandle}.
604 """
605 super(Handle, self).__init__()
606 self._value = self._normalize(aHandle)
607 self.bOwnership = bOwnership
608 if Handle.__bLeakDetection: # XXX DEBUG
609 print("INIT HANDLE (%r) %r" % (self.value, self))
610
611 @property
612 def value(self):
613 return self._value
614
615 def __del__(self):
616 """
617 Closes the Win32 handle when the Python object is destroyed.
618 """
619 try:
620 if Handle.__bLeakDetection: # XXX DEBUG
621 print("DEL HANDLE %r" % self)
622 self.close()
623 except Exception:
624 pass
625
626 def __enter__(self):
627 """
628 Compatibility with the "C{with}" Python statement.
629 """

Callers 9

GetStdHandleFunction · 0.85
CreateMutexAFunction · 0.85
CreateMutexWFunction · 0.85
OpenMutexAFunction · 0.85
OpenMutexWFunction · 0.85
CreateEventAFunction · 0.85
CreateEventWFunction · 0.85
OpenEventAFunction · 0.85
OpenEventWFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected