當前位置: 首頁>>代碼示例>>Python>>正文


Python win32api.CloseHandle方法代碼示例

本文整理匯總了Python中win32api.CloseHandle方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.CloseHandle方法的具體用法?Python win32api.CloseHandle怎麽用?Python win32api.CloseHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32api的用法示例。


在下文中一共展示了win32api.CloseHandle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testCleanup1

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testCleanup1(self):
        # We used to clobber all outstanding exceptions.
        def f1(invalidate):
            import win32event
            h = win32event.CreateEvent(None, 0, 0, None)
            if invalidate:
                win32api.CloseHandle(int(h))
            1/0
            # If we invalidated, then the object destruction code will attempt 
            # to close an invalid handle.  We don't wan't an exception in 
            # this case

        def f2(invalidate):
            """ This function should throw an IOError. """
            try:
                f1(invalidate)
            except ZeroDivisionError, exc:
                raise IOError("raise 2") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:handles.py

示例2: send_startup_event

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def send_startup_event():
    if sys.platform == 'win32':
        try:
            import win32event
            import win32api
        except:
            return

        try:
            if DEBUG:
                log('bg::send_startup_event')
            startupEvent = win32event.CreateEvent(None, 0, 0, 'startupEvent')
            win32event.SetEvent(startupEvent)
            win32api.CloseHandle(startupEvent)
            if DEBUG:
                log('bg::send_startup_event: done')
        except:
            log_exc() 
開發者ID:alesnav,項目名稱:p2ptv-pi,代碼行數:20,代碼來源:BackgroundProcess.py

示例3: genProcesses

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def genProcesses(self):

            CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
            Process32First = ctypes.windll.kernel32.Process32First
            Process32Next = ctypes.windll.kernel32.Process32Next
            CloseHandle = ctypes.windll.kernel32.CloseHandle

            hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
            pe32 = PROCESSENTRY32()
            pe32.dwSize = ctypes.sizeof(PROCESSENTRY32)
            if Process32First(hProcessSnap, ctypes.byref(pe32)) == win32con.FALSE:
                print(sys.stderr, "Failed getting first process.")
                return

            while True:
                yield pe32
                if Process32Next(hProcessSnap, ctypes.byref(pe32)) == win32con.FALSE:
                    break

            CloseHandle(hProcessSnap) 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:22,代碼來源:file.py

示例4: genProcesses

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def genProcesses(self):

            CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
            Process32First = ctypes.windll.kernel32.Process32First
            Process32Next = ctypes.windll.kernel32.Process32Next
            CloseHandle = ctypes.windll.kernel32.CloseHandle

            hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
            pe32 = PROCESSENTRY32()
            pe32.dwSize = ctypes.sizeof(PROCESSENTRY32)
            if Process32First(hProcessSnap, ctypes.byref(pe32)) == win32con.FALSE:
                print("Failed getting first process.")
                return

            while True:
                yield pe32
                if Process32Next(hProcessSnap, ctypes.byref(pe32)) == win32con.FALSE:
                    break

            CloseHandle(hProcessSnap) 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:22,代碼來源:process.py

示例5: closeApp

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def closeApp(self, hProcess, title):
            """
            Close Application by window title
            """

            try:
                win32gui.EnumWindows(FileWriterLauncherGui.enumCallback, title)

                if proc is not None:
                    win32event.WaitForSingleObject(hProcess, 5 * 1000)
                    win32api.CloseHandle(hProcess)

                    for pid in self.genChildProcesses(proc):
                        try:
                            handle = win32api.OpenProcess(1, False, pid)
                            win32process.TerminateProcess(handle, -1)
                            win32api.CloseHandle(handle)
                        except:
                            pass

            except:
                pass 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:24,代碼來源:process.py

示例6: socket_bind_recv

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def socket_bind_recv(socket_fn, cmd_handler):
    """
    非bsd係統的進程間通信,接受消息,處理消息,使用windows全局共享內存實現,
    函數名稱保持與bsd的接口名稱一致
    :param socket_fn: 共享內存文件名稱
    :param cmd_handler: cmd處理函數,callable類型
    """
    if not callable(cmd_handler):
        print('socket_bind_recv cmd_handler must callable!')

    while True:
        global_fn = 'Global\\{}'.format(socket_fn)
        event = w32e.CreateEvent(None, 0, 0, global_fn)
        event_mmap = mmf.mmapfile(None, socket_fn, 1024)
        w32e.WaitForSingleObject(event, -1)
        socket_cmd = event_mmap.read(1024).decode()
        # 把接收到的socket傳遞給外部對應的處理函數
        cmd_handler(socket_cmd)
        event_mmap.close()
        win_api.CloseHandle(event) 
開發者ID:bbfamily,項目名稱:abu,代碼行數:22,代碼來源:ABuWinUtil.py

示例7: cleanup

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def cleanup(self):
		try:
			common.internal_print("Shutting down module: RDP Dynamic Virtual Channel")
			common.internal_print("Please exit XFLTReaT...")
			win32api.CloseHandle(self.comms_socket)
		except Exception as e:
			pass

		if self.serverorclient:
			self.packetselector.delete_client(self.client) 
開發者ID:earthquake,項目名稱:XFLTReaT,代碼行數:12,代碼來源:RDP.py

示例8: testCleanup2

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testCleanup2(self):
        # Cause an exception during object destruction.
        # The worst this does is cause an ".XXX undetected error (why=3)" 
        # So avoiding that is the goal
        import win32event
        h = win32event.CreateEvent(None, 0, 0, None)
        # Close the handle underneath the object.
        win32api.CloseHandle(int(h))
        # Object destructor runs with the implicit close failing
        h = None 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:handles.py

示例9: testCleanup3

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testCleanup3(self):
        # And again with a class - no __del__
        import win32event
        class Test:
            def __init__(self):
                self.h = win32event.CreateEvent(None, 0, 0, None)
                win32api.CloseHandle(int(self.h))
        t=Test()
        t = None 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:handles.py

示例10: testCleanupGood

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testCleanupGood(self):
        # And check that normal error semantics *do* work.
        import win32event
        h = win32event.CreateEvent(None, 0, 0, None)
        win32api.CloseHandle(int(h))
        self.assertRaises(win32api.error, h.Close)
        # A following Close is documented as working
        h.Close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:handles.py

示例11: _getInvalidHandleException

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def _getInvalidHandleException(self):
        try:
            win32api.CloseHandle(1)
        except win32api.error, exc:
            return exc 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_exceptions.py

示例12: testFuncIndex

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testFuncIndex(self):
        exc = self._getInvalidHandleException()
        self._testExceptionIndex(exc, 1, "CloseHandle") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_exceptions.py

示例13: testUnpack

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testUnpack(self):
        try:
            win32api.CloseHandle(1)
            self.fail("expected exception!")
        except win32api.error, exc:
            self.failUnlessEqual(exc.winerror, winerror.ERROR_INVALID_HANDLE)
            self.failUnlessEqual(exc.funcname, "CloseHandle")
            expected_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
            self.failUnlessEqual(exc.strerror, expected_msg) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_exceptions.py

示例14: testAsStr

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testAsStr(self):
        exc = self._getInvalidHandleException()
        err_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
        # early on the result actually *was* a tuple - it must always look like one
        err_tuple = (winerror.ERROR_INVALID_HANDLE, 'CloseHandle', err_msg)
        self.failUnlessEqual(str(exc), str(err_tuple)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_exceptions.py

示例15: testAsTuple

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import CloseHandle [as 別名]
def testAsTuple(self):
        exc = self._getInvalidHandleException()
        err_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
        # early on the result actually *was* a tuple - it must be able to be one
        err_tuple = (winerror.ERROR_INVALID_HANDLE, 'CloseHandle', err_msg)
        if sys.version_info < (3,):
            self.failUnlessEqual(tuple(exc), err_tuple)
        else:
            self.failUnlessEqual(exc.args, err_tuple) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_exceptions.py


注:本文中的win32api.CloseHandle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。