human
Complete the below
def detached(logfile=None, pidfile=None, uid=None, gid=None, umask=0, workdir=None, fake=False, **opts):

    ''''Detach the current process in the background (daemonize).
    Arguments:
    logfile (str): Optional log file.
    The ability to write to this file
    will be verified before the process is detached.
    pidfile (str): Optional pid file.
    The pidfile won\'t be created,
    as this is the responsibility of the child.  But the process will
    exit if the pid lock exists and the pid written is still running.
    uid (int, str): Optional user id or user name to change
    effective privileges to.
    gid (int, str): Optional group id or group name to change
    effective privileges to.
    umask (str, int): Optional umask that\'ll be effective in
    the child process.
    workdir (str): Optional new working directory.
    fake (bool): Don\'t actually detach, intended for debugging purposes.
    **opts (Any): Ignored.
    Example:
    >>> from celery.platforms import detached, create_pidlock
    >>> with detached(
    ...           logfile=\'/var/log/app.log\',
    ...           pidfile=\'/var/run/app.pid\',
    ...           uid=\'nobody\'):
    ... # Now in detached child process with effective user set to nobody,
    ... # and we know that our logfile can be written to, and that
    ... # the pidfile isn\'t locked.
    ... pidlock = create_pidlock(\'/var/run/app.pid\')
    ... # Run the program
    ... program.run(logfile=\'/var/log/app.log\')'
    '''
assistant
#Here is the Python code you requested.
    if (not resource):
        raise RuntimeError(u'This    platform    does    not    support    detach.')
    workdir = (os.getcwd() if (workdir is None) else workdir)
    signals.reset(u'SIGCLD')
    maybe_drop_privileges(uid=uid, gid=gid)
    def after_chdir_do():
        (logfile and open(logfile, u'a').close())
        if pidfile:
            _create_pidlock(pidfile).release()
    return DaemonContext(umask=umask, workdir=workdir, fake=fake, after_chdir=after_chdir_do)