def kill_process(procname, scriptname):

    # from http://stackoverflow.com/a/2940878
    import subprocess, signal
    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
    out, err = p.communicate()

    for line in out.decode().splitlines():
        if procname in line and scriptname in line:
            pid = int(line.split()[1])
            info('Stopping %s %s %d' % (procname, scriptname, pid))
            os.kill(pid, signal.SIGKILL)
kill WSGI processes that may be running in development
dataset/ETHPy150Open geopython/pycsw/pavement.py/kill_process