def stopWorker(basedir, quiet, signame="TERM"):
    """
    Stop worker process by sending it a signal.

    Using the specified basedir path, read worker process's pid file and
    try to terminate that process with specified signal.

    @param basedir: worker's basedir path
    @param   quite: if False, don't print any messages to stdout
    @param signame: signal to send to the worker process

    @raise WorkerNotRunning: if worker pid file is not found
    """
    import signal

    os.chdir(basedir)
    try:
        f = open("twistd.pid", "rt")
    except IOError:
        raise WorkerNotRunning()

    pid = int(f.read().strip())
    signum = getattr(signal, "SIG" + signame)
    timer = 0
    try:
        os.kill(pid, signum)
    except OSError as e:
        if e.errno != 3:
            raise

    time.sleep(0.1)
    while timer < 10:
        # poll once per second until twistd.pid goes away, up to 10 seconds
        try:
            os.kill(pid, 0)
        except OSError:
            if not quiet:
                print("worker process {0} is dead".format(pid))
            return 0
        timer += 1
        time.sleep(1)
    if not quiet:
        print("never saw process go away")
    return 1
Stop worker process by sending it a signal.

    Using the specified basedir path, read worker process's pid file and
    try to terminate that process with specified signal.

    @param basedir: worker's basedir path
    @param   quite: if False, don't print any messages to stdout
    @param signame: signal to send to the worker process

    @raise WorkerNotRunning: if worker pid file is not found