def _setup_ulimit_time_limit(self, hardtimelimit, cgroups):
        """Setup time limit with ulimit for the current process."""
        if hardtimelimit is not None:
            # Also use ulimit for CPU time limit as a fallback if cgroups don't work.
            if CPUACCT in cgroups:
                # Use a slightly higher limit to ensure cgroups get used
                # (otherwise we cannot detect the timeout properly).
                ulimit = hardtimelimit + _ULIMIT_DEFAULT_OVERHEAD
            else:
                ulimit = hardtimelimit
            resource.setrlimit(resource.RLIMIT_CPU, (ulimit, ulimit))
Setup time limit with ulimit for the current process.