当前位置: 首页>>代码示例>>Python>>正文


Python win32file.CloseHandle方法代码示例

本文整理汇总了Python中win32file.CloseHandle方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.CloseHandle方法的具体用法?Python win32file.CloseHandle怎么用?Python win32file.CloseHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32file的用法示例。


在下文中一共展示了win32file.CloseHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _OpenFileForRead

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def _OpenFileForRead(self, path):
        try:
            fhandle = self.fhandle = win32file.CreateFile(
                path,
                win32file.GENERIC_READ,
                win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_ATTRIBUTE_NORMAL,
                None)

            self._closer = weakref.ref(
                self, lambda x: win32file.CloseHandle(fhandle))

            self.write_enabled = False
            return fhandle

        except pywintypes.error as e:
            raise IOError("Unable to open %s: %s" % (path, e)) 
开发者ID:google,项目名称:rekall,代码行数:21,代码来源:win32.py

示例2: _OpenFileForWrite

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def _OpenFileForWrite(self, path):
        try:
            fhandle = self.fhandle = win32file.CreateFile(
                path,
                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_ATTRIBUTE_NORMAL,
                None)
            self.write_enabled = True
            self._closer = weakref.ref(
                self, lambda x: win32file.CloseHandle(fhandle))

            return fhandle

        except pywintypes.error as e:
            raise IOError("Unable to open %s: %s" % (path, e)) 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:win32.py

示例3: main

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def main():
    
    #=== open the TUN/TAP interface
    
    tuntap = openTunTap()
    
    #=== start read/write threads
    
    writeThread = WriteThread(tuntap)
    readThread  = ReadThread(tuntap,writeThread.transmit)
    
    readThread.start()
    writeThread.start()
    
    #=== wait for Enter to stop
    
    raw_input("Press enter to stop...\n")
    
    readThread.close()
    writeThread.close()
    win32file.CloseHandle(tuntap) 
开发者ID:alexsunday,项目名称:pyvpn,代码行数:23,代码来源:tun-ping-responder.py

示例4: testCompletionPortsMultiple

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def testCompletionPortsMultiple(self):
        # Mainly checking that we can "associate" an existing handle.  This
        # failed in build 203.
        ioport = win32file.CreateIoCompletionPort(win32file.INVALID_HANDLE_VALUE,
                                                  0, 0, 0)
        socks = []
        for PORT in range(9123, 9125):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.bind(('', PORT))
            sock.listen(1)
            socks.append(sock)
            new = win32file.CreateIoCompletionPort(sock.fileno(), ioport, PORT, 0)
            assert new is ioport
        for s in socks:
            s.close()
        hv = int(ioport)
        ioport = new = None
        # The handle itself should be closed now (unless we leak references!)
        # Check that.
        try:
            win32file.CloseHandle(hv)
            raise RuntimeError("Expected close to fail!")
        except win32file.error, details:
            self.failUnlessEqual(details.winerror, winerror.ERROR_INVALID_HANDLE) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_win32file.py

示例5: _watcherThread

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def _watcherThread(self, dn, dh, changes):
        # A synchronous version:
        # XXX - not used - I was having a whole lot of problems trying to
        # get this to work.  Specifically:
        # * ReadDirectoryChangesW without an OVERLAPPED blocks infinitely.
        # * If another thread attempts to close the handle while
        #   ReadDirectoryChangesW is waiting on it, the ::CloseHandle() method
        #   blocks (which has nothing to do with the GIL - it is correctly
        #   managed)
        # Which ends up with no way to kill the thread!
        flags = win32con.FILE_NOTIFY_CHANGE_FILE_NAME
        while 1:
            try:
                print "waiting", dh
                changes = win32file.ReadDirectoryChangesW(dh,
                                                          8192,
                                                          False, #sub-tree
                                                          flags)
                print "got", changes
            except:
                raise
            changes.extend(changes) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_win32file.py

示例6: close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def close(self, filepath):
        """
        Close open port.

        :param filepath: File to close.
        """
        hFile = None
        path = self.ports[filepath]["path"]
        if path is not None:
            if path in list(self.files.keys()):
                hFile = self.files[path]
                del self.files[path]
            if hFile is not None:
                try:
                    win32file.CloseHandle(hFile)
                except win32file.error as inst:
                    print("FAIL: Closing the file: " + str(inst))
                    return
        print("PASS: Close") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:21,代码来源:virtio_console_guest.py

示例7: csv_export_ram

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def csv_export_ram(self):
        """Dump ram using winpmem"""
        hSvc = create_driver_service(self.logger)
        start_service(hSvc, self.logger)
        try:
            fd = win32file.CreateFile(
                "\\\\.\\pmem",
                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_ATTRIBUTE_NORMAL,
                None)
            try:
                t = time.time()
                image = _Image(fd)
                self.logger.info("Imaging to " + self.output_dir + '\\' + self.computer_name + '_memdump.raw')
                image.DumpWithRead(self.output_dir + '\\' + self.computer_name + '_memdump.raw')
                self.logger.info("Completed in %s seconds" % (time.time() - t))
            finally:
                win32file.CloseHandle(fd)
        finally:
            stop_and_delete_driver_service(hSvc) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:25,代码来源:dump.py

示例8: Stop

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def Stop(self):
        """
        This will be called to stop the thread.
        """
        if self.file:
            writeOvlap = win32file.OVERLAPPED()
            writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None)
            msg = "q".encode("ascii")
            win32file.WriteFile(self.file, msg, writeOvlap)
            win32file.CloseHandle(self.file)
            self.file = None
        self.keepRunning = False

        if self.service:
            win32service.CloseServiceHandle(self.service)

        #eg.PrintNotice("MCE_Vista: stopping thread") 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:19,代码来源:__init__.py

示例9: _closeHandle

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def _closeHandle(h):
    x = win32file.CloseHandle(h)
    assert x != win32file.INVALID_HANDLE_VALUE
    return x 
开发者ID:mbusb,项目名称:multibootusb,代码行数:6,代码来源:win32.py

示例10: win_close_tunnel

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def win_close_tunnel(self, tun):
		try:
			win32file.CloseHandle(self.wintun)
		except:
			pass

		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:9,代码来源:interface.py

示例11: delete_client

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def delete_client(self, client):
		if client in self.clients:

			if self.os_type == common.OS_WINDOWS:
				import win32file

				try:
					win32file.CloseHandle(client.get_pipe_r())
					win32file.CloseHandle(client.get_pipe_w())
				except Exception as e:
					common.internal_print("Remove authenticated client: CloseHandle exception: {0}".format(e), -1)
			else:
				try:
					client.get_pipe_r_fd().close()
					client.get_pipe_w_fd().close()
				except Exception as e:
					common.internal_print("Remove authenticated client: os.close exception: {0}".format(e), -1)

			client.call_stopfp()
			self.clients.remove(client)

		return

	# This function should run from the point when the framework was started.
	# It runs as an infinite loop to read the packets off the tunnel.
	# When an IPv4 packet was found that will be selected and checked whether
	# it addresses a client in the client list. If a client was found, then the
	# packet will be written on that pipe. 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:30,代码来源:packetselector.py

示例12: close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def close(self):
        win32file.CloseHandle(self.fhandle) 
开发者ID:google,项目名称:rekall,代码行数:4,代码来源:win32.py

示例13: OnDeviceChange

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def OnDeviceChange(hwnd, msg, wp, lp):
    # Unpack the 'lp' into the appropriate DEV_BROADCAST_* structure,
    # using the self-identifying data inside the DEV_BROADCAST_HDR.
    info = win32gui_struct.UnpackDEV_BROADCAST(lp)
    print "Device change notification:", wp, str(info)
    if wp==win32con.DBT_DEVICEQUERYREMOVE and info.devicetype==win32con.DBT_DEVTYP_HANDLE:
        # Our handle is stored away in the structure - just close it
        print "Device being removed - closing handle"
        win32file.CloseHandle(info.handle)
        # and cancel our notifications - if it gets plugged back in we get
        # the same notification and try and close the same handle...
        win32gui.UnregisterDeviceNotification(info.hdevnotify)
    return True 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:win32gui_devicenotify.py

示例14: exit_threads

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def exit_threads(self):
        """
        Function end all running data switch.
        """
        self.exit_thread.set()
        for th in self.threads:
            print("join")
            th.join()
        self.exit_thread.clear()

        del self.threads[:]
        for desc in six.itervalues(self.files):
            win32file.CloseHandle(desc)
        self.files.clear()
        print("PASS: All threads finished") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:17,代码来源:virtio_console_guest.py

示例15: conn_loop

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CloseHandle [as 别名]
def conn_loop(self):
        self.is_running = True
        self.update_vars()
        self.file_handle = win32file.CreateFile(
            self.ipc_path,
            win32file.GENERIC_READ | win32file.GENERIC_WRITE,
            0, None,
            win32file.OPEN_EXISTING,
            0, None
        )
        while self.is_running:
            try:
                while not self.write_queue.empty():
                    win32file.WriteFile(
                        self.file_handle, self.write_queue.get_nowait())
            except win32file.error:
                logger.debug('Exception while writing to pipe.', exc_info=True)
                self.is_running = False
                break
            size = win32file.GetFileSize(self.file_handle)
            if size > 0:
                while size > 0:
                    # pipe has data to read
                    _, data = win32file.ReadFile(self.file_handle, 4096)
                    self.on_data(data)
                    size = win32file.GetFileSize(self.file_handle)
            else:
                time.sleep(1)
        win32file.CloseHandle(self.file_handle)
        logger.debug('Pipe closed.') 
开发者ID:iamkroot,项目名称:trakt-scrobbler,代码行数:32,代码来源:mpv.py


注:本文中的win32file.CloseHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。