當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。