当前位置: 首页>>代码示例>>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;未经允许,请勿转载。