def daemonize(username=""):
    # set the limit of open files for ddd
    soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)

    if hard <= settings.LIMIT_OPEN_FILES:

        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (settings.LIMIT_OPEN_FILES, hard))
        except Exception, e:
            logging.getLogger('worker').error("Setting ressource limit failed: RLIMT_NOFILE [%r,%r] --> [%r,%r] (%r)" % (soft, hard, settings.LIMIT_OPEN_FILES, hard, e))
            raise e
    else:
        logging.getLogger('worker').info("Current RLIMIT_NOFILE is smaller than settings -> do not change: [soft=%r, hard=%r]" % (soft, hard))

    #
    if os.fork() != 0:
        os._exit(0)
    os.setsid()
    if os.name != 'nt':
        import pwd
        if username:
            uid = pwd.getpwnam(username)[2]
            os.setuid(uid)
    if os.fork() != 0:
        os._exit(0)
    # create the pidfile
    pidfile = file(settings.PIDFILE, "w")
    pidfile.write("%d\n" % os.getpid())
    pidfile.close()
    # register a cleanup callback
    pidfile = os.path.abspath(settings.PIDFILE)

    def delpidfile():
        os.remove(pidfile)
    atexit.register(delpidfile)

    def delpidfileonSIGTERM(a, b):
        sys.exit()
    signal.signal(signal.SIGTERM, delpidfileonSIGTERM)
    #
    os.chdir("/")
    f = os.open(os.devnull, os.O_RDONLY)
    os.dup2(f, sys.stdin.fileno())
    os.close(f)
    f = os.open(os.devnull, os.O_WRONLY)
    os.dup2(f, sys.stdout.fileno())
    os.close(f)
    f = os.open(os.devnull, os.O_WRONLY)
    os.dup2(f, sys.stderr.fileno())
    os.close(f)
dataset/ETHPy150Open mikrosimage/OpenRenderManagement/src/octopus/workerd.py/daemonize/swapped operands of `<=`