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


Python resource.error方法代码示例

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


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

示例1: test_handles_closed_on_exception

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_handles_closed_on_exception(self):
        # If CreateProcess exits with an error, ensure the
        # duplicate output handles are released
        ifhandle, ifname = tempfile.mkstemp()
        ofhandle, ofname = tempfile.mkstemp()
        efhandle, efname = tempfile.mkstemp()
        try:
            subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
              stderr=efhandle)
        except OSError:
            os.close(ifhandle)
            os.remove(ifname)
            os.close(ofhandle)
            os.remove(ofname)
            os.close(efhandle)
            os.remove(efname)
        self.assertFalse(os.path.exists(ifname))
        self.assertFalse(os.path.exists(ofname))
        self.assertFalse(os.path.exists(efname)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_subprocess.py

示例2: __enter__

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def __enter__(self):
        """Try to save previous ulimit, then set it to (0, 0)."""
        if resource is not None:
            try:
                self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
                resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
            except (ValueError, resource.error):
                pass

        if sys.platform == 'darwin':
            # Check if the 'Crash Reporter' on OSX was configured
            # in 'Developer' mode and warn that it will get triggered
            # when it is.
            #
            # This assumes that this context manager is used in tests
            # that might trigger the next manager.
            value = subprocess.Popen(['/usr/bin/defaults', 'read',
                    'com.apple.CrashReporter', 'DialogType'],
                    stdout=subprocess.PIPE).communicate()[0]
            if value.strip() == b'developer':
                print "this tests triggers the Crash Reporter, that is intentional"
                sys.stdout.flush() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_subprocess.py

示例3: find_available_port

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def find_available_port(port_range=(49152, 65535), max_tries=1000):
        low, high = port_range

        port = low
        try_no = 0

        while try_no < max_tries:
            try_no += 1
            port = random.randint(low, high)
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                sock.bind(('localhost', port))
            except socket.error as e:
                if e.errno == errno.EADDRINUSE:
                    continue
                raise
            finally:
                sock.close()

            break
        else:
            port = None

        return port 
开发者ID:edgedb,项目名称:edgedb,代码行数:26,代码来源:main.py

示例4: test_handles_closed_on_exception

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_handles_closed_on_exception(self):
        # If CreateProcess exits with an error, ensure the
        # duplicate output handles are released
        ifhandle, ifname = mkstemp()
        ofhandle, ofname = mkstemp()
        efhandle, efname = mkstemp()
        try:
            subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
              stderr=efhandle)
        except OSError:
            os.close(ifhandle)
            os.remove(ifname)
            os.close(ofhandle)
            os.remove(ofname)
            os.close(efhandle)
            os.remove(efname)
        self.assertFalse(os.path.exists(ifname))
        self.assertFalse(os.path.exists(ofname))
        self.assertFalse(os.path.exists(efname)) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_subprocess.py

示例5: __exit__

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def __exit__(self, *args):
        """Return core file behavior to default."""
        if self.old_limit is None:
            return
        if resource is not None:
            try:
                resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
            except (ValueError, resource.error):
                pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_subprocess.py

示例6: test_preexec_errpipe_does_not_double_close_pipes

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_preexec_errpipe_does_not_double_close_pipes(self):
        """Issue16140: Don't double close pipes on preexec error."""

        def raise_it():
            raise RuntimeError("force the _execute_child() errpipe_data path.")

        with self.assertRaises(RuntimeError):
            self._TestExecuteChildPopen(
                    self, [sys.executable, "-c", "pass"],
                    stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE, preexec_fn=raise_it) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_subprocess.py

示例7: test_wait_when_sigchild_ignored

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def test_wait_when_sigchild_ignored(self):
        # NOTE: sigchild_ignore.py may not be an effective test on all OSes.
        sigchild_ignore = test_support.findfile("sigchild_ignore.py",
                                                subdir="subprocessdata")
        p = subprocess.Popen([sys.executable, sigchild_ignore],
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        self.assertEqual(0, p.returncode, "sigchild_ignore.py exited"
                         " non-zero with this error:\n%s" % stderr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_subprocess.py

示例8: bump_rlimit_nofile

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def bump_rlimit_nofile() -> None:
    try:
        fno_soft, fno_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
    except resource.error:
        logger.warning('could not read RLIMIT_NOFILE')
    else:
        if fno_soft < defines.EDGEDB_MIN_RLIMIT_NOFILE:
            try:
                resource.setrlimit(
                    resource.RLIMIT_NOFILE,
                    (min(defines.EDGEDB_MIN_RLIMIT_NOFILE, fno_hard),
                     fno_hard))
            except resource.error:
                logger.warning('could not set RLIMIT_NOFILE') 
开发者ID:edgedb,项目名称:edgedb,代码行数:16,代码来源:main.py

示例9: set_monitor

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def set_monitor():
    """Sets up a following call to daemonize() to fork a supervisory process to
    monitor the daemon and restart it if it dies due to an error signal."""
    global _monitor
    _monitor = True 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:7,代码来源:daemon.py

示例10: _fork_notify_startup

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _fork_notify_startup(fd):
    if fd is not None:
        error, bytes_written = ovs.socket_util.write_fully(fd, "0")
        if error:
            sys.stderr.write("could not write to pipe\n")
            sys.exit(1)
        os.close(fd) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:9,代码来源:daemon.py

示例11: _suppress_core_files

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _suppress_core_files(self):
            """Try to prevent core files from being created.
            Returns previous ulimit if successful, else None.
            """
            try:
                import resource
                old_limit = resource.getrlimit(resource.RLIMIT_CORE)
                resource.setrlimit(resource.RLIMIT_CORE, (0,0))
                return old_limit
            except (ImportError, ValueError, resource.error):
                return None 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:13,代码来源:test_subprocess.py

示例12: _unsuppress_core_files

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def _unsuppress_core_files(self, old_limit):
            """Return core file behavior to default."""
            if old_limit is None:
                return
            try:
                import resource
                resource.setrlimit(resource.RLIMIT_CORE, old_limit)
            except (ImportError, ValueError, resource.error):
                return 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:11,代码来源:test_subprocess.py

示例13: mkdir

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def mkdir(path):
    """Make directory at the specified local path with special error handling.
    """
    try:
        os.makedirs(path)
    except OSError as exc:  # Python >2.5
        if exc.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise 
开发者ID:awslabs,项目名称:autogluon,代码行数:12,代码来源:files.py

示例14: raise_num_file

# 需要导入模块: import resource [as 别名]
# 或者: from resource import error [as 别名]
def raise_num_file(nofile_atleast=4096):
    try:
        import resource as res
    except ImportError: #Windows
        res = None
    if res is None:
        return (None,)*2
    # what is current ulimit -n setting?
    soft,ohard = res.getrlimit(res.RLIMIT_NOFILE)
    hard = ohard
    # increase limit (soft and even hard) if needed
    if soft < nofile_atleast:
        soft = nofile_atleast

        if hard<soft:
            hard = soft

        #logger.warning('setting soft & hard ulimit -n {} {}'.format(soft,hard))
        try:
            res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
        except (ValueError,res.error):
            try:
               hard = soft
               logger.warning('trouble with max limit, retrying with soft,hard {},{}'.format(soft,hard))
               res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
            except Exception:
               logger.warning('failed to set ulimit')
               soft,hard = res.getrlimit(res.RLIMIT_NOFILE)

    return soft,hard 
开发者ID:awslabs,项目名称:autogluon,代码行数:32,代码来源:files.py


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