• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python msvcrt.open_osfhandle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msvcrt.open_osfhandle函数的典型用法代码示例。如果您正苦于以下问题:Python open_osfhandle函数的具体用法?Python open_osfhandle怎么用?Python open_osfhandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __init__

 def __init__(self, args, stdin=None, stdout=None, stderr=None, **kwds):
     stdin_rfd = stdout_wfd = stderr_wfd = None
     stdin_wh = stdout_rh = stderr_rh = None
     if stdin == PIPE:
         stdin_rh, stdin_wh = pipe(overlapped=(False, True))
         stdin_rfd = msvcrt.open_osfhandle(stdin_rh, os.O_RDONLY)
     if stdout == PIPE:
         stdout_rh, stdout_wh = pipe(overlapped=(True, False))
         stdout_wfd = msvcrt.open_osfhandle(stdout_wh, 0)
     if stderr == PIPE:
         stderr_rh, stderr_wh = pipe(overlapped=(True, False))
         stderr_wfd = msvcrt.open_osfhandle(stderr_wh, 0)
     try:
         super().__init__(args, bufsize=0, universal_newlines=False,
                          stdin=stdin_rfd, stdout=stdout_wfd,
                          stderr=stderr_wfd, **kwds)
     except:
         for h in (stdin_wh, stdout_rh, stderr_rh):
             _winapi.CloseHandle(h)
         raise
     else:
         if stdin_wh is not None:
             self.stdin = PipeHandle(stdin_wh)
         if stdout_rh is not None:
             self.stdout = PipeHandle(stdout_rh)
         if stderr_rh is not None:
             self.stderr = PipeHandle(stderr_rh)
     finally:
         if stdin == PIPE:
             os.close(stdin_rfd)
         if stdout == PIPE:
             os.close(stdout_wfd)
         if stderr == PIPE:
             os.close(stderr_wfd)
开发者ID:nerodong,项目名称:tulip,代码行数:34,代码来源:windows_utils.py


示例2: override_io

def override_io():
    old_out = sys.stdout
    old_err = sys.stderr

    fd_out = int(os.environ['TEST_WRITE_OUT'])
    fd_err = int(os.environ['TEST_WRITE_ERR'])
    if sys.platform == 'win32':
        import msvcrt
        fd_out = msvcrt.open_osfhandle(fd_out, 0)
        fd_err = msvcrt.open_osfhandle(fd_err, 0)
    api_out = os.fdopen(fd_out, 'w')
    api_err = os.fdopen(fd_err, 'w')

    class Intercept:
        def __init__(self, api, old):
            self.api = api
            self.old = old

        def write(self, data):
            import threading
            if threading.current_thread().name.startswith('APIThread'):
                self.api.write(data)
            else:
                self.old.write(data)

        def flush(self):
            self.api.flush()
            self.old.flush()

    sys.stdout = Intercept(api_out, old_out)
    sys.stderr = Intercept(api_err, old_err)
开发者ID:K-Carrington,项目名称:dronekit-python,代码行数:31,代码来源:testlib.py


示例3: run

    def run(self):
        """Set up input/output streams and execute the child function in a new
        thread.  This is part of the `threading.Thread` interface and should
        not be called directly.
        """
        if self.f is None:
            return
        if self.stdin is not None:
            sp_stdin = io.TextIOWrapper(self.stdin)
        else:
            sp_stdin = io.StringIO("")

        if ON_WINDOWS:
            if self.c2pwrite != -1:
                self.c2pwrite = msvcrt.open_osfhandle(self.c2pwrite.Detach(), 0)
            if self.errwrite != -1:
                self.errwrite = msvcrt.open_osfhandle(self.errwrite.Detach(), 0)

        if self.c2pwrite != -1:
            sp_stdout = io.TextIOWrapper(io.open(self.c2pwrite, 'wb', -1))
        else:
            sp_stdout = sys.stdout
        if self.errwrite == self.c2pwrite:
            sp_stderr = sp_stdout
        elif self.errwrite != -1:
            sp_stderr = io.TextIOWrapper(io.open(self.errwrite, 'wb', -1))
        else:
            sp_stderr = sys.stderr

        r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr)
        self.returncode = 0 if r is None else r
开发者ID:ArRolin,项目名称:gitsome,代码行数:31,代码来源:proc.py


示例4: _get_handles

        def _get_handles(self, stdin, stdout, stderr):
            """Construct and return tupel with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            """
            if stdin == None and stdout == None and stderr == None:
                return (None, None, None, None, None, None)

            p2cread, p2cwrite = None, None
            c2pread, c2pwrite = None, None
            errread, errwrite = None, None

            if stdin == None:
                p2cread = GetStdHandle(STD_INPUT_HANDLE)
            elif stdin == PIPE:
                p2cread, p2cwrite = CreatePipe(None, 0)
                # Detach and turn into fd
                p2cwrite = p2cwrite.Detach()
                p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
            elif type(stdin) == int:
                p2cread = msvcrt.get_osfhandle(stdin)
            else:
                # Assuming file-like object
                p2cread = msvcrt.get_osfhandle(stdin.fileno())
            p2cread = self._make_inheritable(p2cread)

            if stdout == None:
                c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
            elif stdout == PIPE:
                c2pread, c2pwrite = CreatePipe(None, 0)
                # Detach and turn into fd
                c2pread = c2pread.Detach()
                c2pread = msvcrt.open_osfhandle(c2pread, 0)
            elif type(stdout) == int:
                c2pwrite = msvcrt.get_osfhandle(stdout)
            else:
                # Assuming file-like object
                c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
            c2pwrite = self._make_inheritable(c2pwrite)

            if stderr == None:
                errwrite = GetStdHandle(STD_ERROR_HANDLE)
            elif stderr == PIPE:
                errread, errwrite = CreatePipe(None, 0)
                # Detach and turn into fd
                errread = errread.Detach()
                errread = msvcrt.open_osfhandle(errread, 0)
            elif stderr == STDOUT:
                errwrite = c2pwrite
            elif type(stderr) == int:
                errwrite = msvcrt.get_osfhandle(stderr)
            else:
                # Assuming file-like object
                errwrite = msvcrt.get_osfhandle(stderr.fileno())
            errwrite = self._make_inheritable(errwrite)

            return (p2cread, p2cwrite,
                    c2pread, c2pwrite,
                    errread, errwrite)
开发者ID:terrasea,项目名称:pastescript,代码行数:58,代码来源:subprocess24.py


示例5: __init__

    def __init__(self, args, bufsize = 0, executable = None, stdin = None, stdout = None, stderr = None, preexec_fn = None, close_fds = False, shell = False, cwd = None, env = None, universal_newlines = False, startupinfo = None, creationflags = 0):
        """Create new Popen instance."""
        _cleanup()
        if not isinstance(bufsize, (int, long)):
            raise TypeError('bufsize must be an integer')
        if mswindows:
            if preexec_fn is not None:
                raise ValueError('preexec_fn is not supported on Windows platforms')
            if close_fds and (stdin is not None or stdout is not None or stderr is not None):
                raise ValueError('close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderr')
        else:
            if startupinfo is not None:
                raise ValueError('startupinfo is only supported on Windows platforms')
            if creationflags != 0:
                raise ValueError('creationflags is only supported on Windows platforms')
        self.stdin = None
        self.stdout = None
        self.stderr = None
        self.pid = None
        self.returncode = None
        self.universal_newlines = universal_newlines
        (p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
        try:
            self._execute_child(args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
        except Exception:
            exc_type, exc_value, exc_trace = sys.exc_info()
            for fd in to_close:
                try:
                    if mswindows:
                        fd.Close()
                    else:
                        os.close(fd)
                except EnvironmentError:
                    pass

            raise exc_type, exc_value, exc_trace

        if mswindows:
            if p2cwrite is not None:
                p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
            if c2pread is not None:
                c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
            if errread is not None:
                errread = msvcrt.open_osfhandle(errread.Detach(), 0)
        if p2cwrite is not None:
            self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
        if c2pread is not None:
            if universal_newlines:
                self.stdout = os.fdopen(c2pread, 'rU', bufsize)
            else:
                self.stdout = os.fdopen(c2pread, 'rb', bufsize)
        if errread is not None:
            if universal_newlines:
                self.stderr = os.fdopen(errread, 'rU', bufsize)
            else:
                self.stderr = os.fdopen(errread, 'rb', bufsize)
        return
开发者ID:aevitas,项目名称:wotsdk,代码行数:57,代码来源:libsubprocess.py


示例6: wtrf

def wtrf():
    if sys.platform != "win32":
        wt = int(os.environ['MYHDL_TO_PIPE'])
        rf = int(os.environ['MYHDL_FROM_PIPE'])
    else:
        wt = msvcrt.open_osfhandle(int(os.environ['MYHDL_TO_PIPE']), os.O_APPEND | os.O_TEXT)
        rf = msvcrt.open_osfhandle(int(os.environ['MYHDL_FROM_PIPE']), os.O_RDONLY | os.O_TEXT)

    return wt, rf
开发者ID:cpeppenster,项目名称:myhdl,代码行数:9,代码来源:test_Cosimulation.py


示例7: __init__

 def __init__(self, args, bufsize = 0, executable = None, stdin = None, stdout = None, stderr = None, preexec_fn = None, close_fds = _PLATFORM_DEFAULT_CLOSE_FDS, shell = False, cwd = None, env = None, universal_newlines = False, startupinfo = None, creationflags = 0, restore_signals = True, start_new_session = False, pass_fds = ()):
     _cleanup()
     self._child_created = False
     self._input = None
     self._communication_started = False
     if not isinstance(bufsize, (int, long)):
         raise TypeError('bufsize must be an integer')
     if mswindows:
         if preexec_fn is not None:
             raise ValueError('preexec_fn is not supported on Windows platforms')
         any_stdio_set = stdin is not None or stdout is not None or stderr is not None
         if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
             if any_stdio_set:
                 close_fds = False
             else:
                 close_fds = True
         elif close_fds and any_stdio_set:
             raise ValueError('close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderr')
     else:
         if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
             close_fds = True
         if pass_fds and not close_fds:
             warnings.warn('pass_fds overriding close_fds.', RuntimeWarning)
             close_fds = True
         if startupinfo is not None:
             raise ValueError('startupinfo is only supported on Windows platforms')
         if creationflags != 0:
             raise ValueError('creationflags is only supported on Windows platforms')
     self.args = args
     self.stdin = None
     self.stdout = None
     self.stderr = None
     self.pid = None
     self.returncode = None
     self.universal_newlines = universal_newlines
     p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite = self._get_handles(stdin, stdout, stderr)
     self._execute_child(args, executable, preexec_fn, close_fds, pass_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
     if mswindows:
         if p2cwrite != -1:
             p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
         if c2pread != -1:
             c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
         if errread != -1:
             errread = msvcrt.open_osfhandle(errread.Detach(), 0)
     if p2cwrite != -1:
         self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
     if c2pread != -1:
         if universal_newlines:
             self.stdout = os.fdopen(c2pread, 'rU', bufsize)
         else:
             self.stdout = os.fdopen(c2pread, 'rb', bufsize)
     if errread != -1:
         if universal_newlines:
             self.stderr = os.fdopen(errread, 'rU', bufsize)
         else:
             self.stderr = os.fdopen(errread, 'rb', bufsize)
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:56,代码来源:subprocess32.py


示例8: main

def main():
    import sys
    fd_r = int(sys.argv[1])
    fd_w = int(sys.argv[2])
    
    if platform.system() == 'Windows':
        import msvcrt
        fd_r = msvcrt.open_osfhandle(fd_r, 0)
        fd_w = msvcrt.open_osfhandle(fd_w, 0)
    
    serve(fd_r, fd_w)
    
开发者ID:sam-roth,项目名称:Keypad,代码行数:11,代码来源:server.py


示例9: __init__

        def __init__(self, args, stdin=None, stdout=None, stderr=None, **kwargs):
            self.stdin = self.stdout = self.stderr = None

            stdin_rh = stdin_wh = stdout_rh = stdout_wh = stderr_rh = stderr_wh = None

            if stdin == subprocess.PIPE:
                stdin_rh, stdin_wh = pipe()
                stdin_rfd = msvcrt.open_osfhandle(stdin_rh.Detach(), os.O_RDONLY)
                self.stdin_rh = stdin_rh
            else:
                stdin_rfd = stdin
                self.stdin_rh = None

            if stdout == subprocess.PIPE:
                stdout_rh, stdout_wh = pipe()
                stdout_wfd = msvcrt.open_osfhandle(stdout_wh, 0)
            else:
                stdout_wfd = stdout

            if stderr == subprocess.PIPE:
                stderr_rh, stderr_wh = pipe()
                stderr_wfd = msvcrt.open_osfhandle(stderr_wh, 0)
            elif stderr == subprocess.STDOUT:
                stderr_wfd = stdout_wfd
            else:
                stderr_wfd = stderr

            try:
                super(Popen, self).__init__(args, stdin=stdin_rfd, stdout=stdout_wfd,
                                            stderr=stderr_wfd, **kwargs)
            except:
                for handle in (stdin_rh, stdin_wh, stdout_rh, stdout_wh, stderr_rh, stderr_wh):
                    if handle is not None:
                        win32file.CloseHandle(handle)
                raise
            else:
                if stdin_wh is not None:
                    self.stdin = AsyncFile(stdin_wh, mode='w')
                if stdout_rh is not None:
                    self.stdout = AsyncFile(stdout_rh, mode='r')
                if stderr_rh is not None:
                    self.stderr = AsyncFile(stderr_rh, mode='r')
            finally:
                if stdin == subprocess.PIPE:
                    os.close(stdin_rfd)
                if stdout == subprocess.PIPE:
                    os.close(stdout_wfd)
                if stderr == subprocess.PIPE:
                    os.close(stderr_wfd)
开发者ID:pgiri,项目名称:asyncoro,代码行数:49,代码来源:asyncfile.py


示例10: spawn_main

def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
    '''
    Run code specified by data received over pipe
    '''
    assert is_forking(sys.argv), "Not forking"
    if sys.platform == 'win32':
        import msvcrt
        import _winapi

        if parent_pid is not None:
            source_process = _winapi.OpenProcess(
                _winapi.PROCESS_DUP_HANDLE, False, parent_pid)
        else:
            source_process = None
        try:
            new_handle = reduction.duplicate(pipe_handle,
                                             source_process=source_process)
        finally:
            if source_process is not None:
                _winapi.CloseHandle(source_process)
        fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
    else:
        from . import semaphore_tracker
        semaphore_tracker._semaphore_tracker._fd = tracker_fd
        fd = pipe_handle
    exitcode = _main(fd)
    sys.exit(exitcode)
开发者ID:Eyepea,项目名称:cpython,代码行数:27,代码来源:spawn.py


示例11: _open

    def _open(handle):
        """
        Open a file descriptor for the specified HANDLE (int -> int).

        Closing the file descriptor will also close the handle.
        """
        return msvcrt.open_osfhandle(handle, 0)
开发者ID:Eothred,项目名称:pymad,代码行数:7,代码来源:_libmadx_rpc.py


示例12: __init__

    def __init__(self, process_obj):
        os.environ["MULTIPROCESSING_FORKING_DISABLE"] = "1"
        spawn._Django_old_layout_hack__save()
        prep_data = spawn.get_preparation_data(process_obj._name)

        # read end of pipe will be "stolen" by the child process
        # -- see spawn_main() in spawn.py.
        rhandle, whandle = _winapi.CreatePipe(None, 0)
        wfd = msvcrt.open_osfhandle(whandle, 0)
        cmd = spawn.get_command_line(parent_pid=os.getpid(), pipe_handle=rhandle)
        cmd = " ".join('"%s"' % x for x in cmd)

        with io.open(wfd, "wb", closefd=True) as to_child:
            # start process
            try:
                hp, ht, pid, tid = CreateProcess(spawn.get_executable(), cmd, None, None, False, 0, None, None, None)
                _winapi.CloseHandle(ht)
            except:
                _winapi.CloseHandle(rhandle)
                raise

            # set attributes of self
            self.pid = pid
            self.returncode = None
            self._handle = hp
            self.sentinel = int(hp)

            # send information to child
            context.set_spawning_popen(self)
            try:
                reduction.dump(prep_data, to_child)
                reduction.dump(process_obj, to_child)
            finally:
                context.set_spawning_popen(None)
开发者ID:pombredanne,项目名称:billiard,代码行数:34,代码来源:popen_spawn_win32.py


示例13: from_subprocess

 def from_subprocess(cls, arg):
     arg = int(arg)
     if MS_WINDOWS:
         fd = msvcrt.open_osfhandle(arg, os.O_WRONLY)
     else:
         fd = arg
     return cls(fd)
开发者ID:haypo,项目名称:perf,代码行数:7,代码来源:_utils.py


示例14: __init__

 def __init__(self, args, stdin=None, stdout=None, stderr=None, **kwds):
     assert not kwds.get('universal_newlines')
     assert kwds.get('bufsize', 0) == 0
     stdin_rfd = stdout_wfd = stderr_wfd = None
     stdin_wh = stdout_rh = stderr_rh = None
     if stdin == PIPE:
         stdin_rh, stdin_wh = pipe(overlapped=(False, True), duplex=True)
         stdin_rfd = msvcrt.open_osfhandle(stdin_rh, os.O_RDONLY)
     else:
         stdin_rfd = stdin
     if stdout == PIPE:
         stdout_rh, stdout_wh = pipe(overlapped=(True, False))
         stdout_wfd = msvcrt.open_osfhandle(stdout_wh, 0)
     else:
         stdout_wfd = stdout
     if stderr == PIPE:
         stderr_rh, stderr_wh = pipe(overlapped=(True, False))
         stderr_wfd = msvcrt.open_osfhandle(stderr_wh, 0)
     elif stderr == STDOUT:
         stderr_wfd = stdout_wfd
     else:
         stderr_wfd = stderr
     try:
         super(Popen, self).__init__(args,
                                     stdin=stdin_rfd,
                                     stdout=stdout_wfd,
                                     stderr=stderr_wfd,
                                     **kwds)
     except:
         for h in (stdin_wh, stdout_rh, stderr_rh):
             if h is not None:
                 _winapi.CloseHandle(h)
         raise
     else:
         if stdin_wh is not None:
             self.stdin = PipeHandle(stdin_wh)
         if stdout_rh is not None:
             self.stdout = PipeHandle(stdout_rh)
         if stderr_rh is not None:
             self.stderr = PipeHandle(stderr_rh)
     finally:
         if stdin == PIPE:
             os.close(stdin_rfd)
         if stdout == PIPE:
             os.close(stdout_wfd)
         if stderr == PIPE:
             os.close(stderr_wfd)
开发者ID:JioCloudCompute,项目名称:trollius,代码行数:47,代码来源:windows_utils.py


示例15: _open

 def _open(self):
   """Opens the current file without handle inheritance."""
   if self.encoding is None:
     with open(self.baseFilename, self.mode) as stream:
       newosf = _duplicate(msvcrt.get_osfhandle(stream.fileno()))
       new_fd = msvcrt.open_osfhandle(newosf, os.O_APPEND)
       return os.fdopen(new_fd, self.mode)
   return codecs.open(self.baseFilename, self.mode, self.encoding)
开发者ID:nodirt,项目名称:luci-py,代码行数:8,代码来源:logging_utils.py


示例16: _recv_item

def _recv_item(connection, item):
    """receive one item. If it's a FileObject, unwrap it."""
    if isinstance(item, _FileObject):
        handle = recv_handle(connection)
        if sys.platform == 'win32':
            handle = msvcrt.open_osfhandle(handle, os.O_RDONLY)
        return os.fdopen(handle, 'rb')
    return item
开发者ID:Bajoo,项目名称:client-pc,代码行数:8,代码来源:process_transmission.py


示例17: detach_fd

    def detach_fd(self):
        """
        Open a file descriptor for the HANDLE and release ownership.

        Closing the file descriptor will also close the handle.
        """
        fd = msvcrt.open_osfhandle(self.handle, 0)
        self.handle = None
        return fd
开发者ID:gitcyc,项目名称:cpymad,代码行数:9,代码来源:windows.py


示例18: open_handle

 def open_handle(handle, mode):
     flags = 0
     if 'w' not in mode and '+' not in mode:
         flags |= os.O_RDONLY
     if 'b' not in mode:
         flags |= os.O_TEXT
     if 'a' in mode:
         flags |= os.O_APPEND
     return msvcrt.open_osfhandle(handle, flags)
开发者ID:marcosptf,项目名称:fedora,代码行数:9,代码来源:ipc.py


示例19: getOsFileHandle

def getOsFileHandle(pipe, flags):
	# Get file descriptor from argument
	pipe = int(pipe)
	if platform == "win32": # windows
		pipeoutfd = open_osfhandle(pipe, flags)
	else: # linux
		pipeoutfd = pipe
	
	return pipeoutfd
开发者ID:abbad,项目名称:NetProb,代码行数:9,代码来源:udp_tcp_client_unnamed_pipes.py


示例20: __init__

    def __init__(self, fd, mode):
        assert mode in ('r', 'w')
        self._mode = mode

        flags = os.O_APPEND | os.O_BINARY
        flags |= os.O_RDONLY if mode == 'r' else os.O_WRONLY
        handle = open_osfhandle(fd, flags)
        self._f = os.fdopen(handle, mode + 'b')
        self._h = handle
        self._fd = fd
开发者ID:B-Rich,项目名称:ctk,代码行数:10,代码来源:pipe_win32.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msvcrt.putch函数代码示例发布时间:2022-05-27
下一篇:
Python msvcrt.locking函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap