def clean_shut():
    print('Clean shut performed')
try:
    os.unlink('WORKER_NAME.%d' % PID)
except:
    pass

def main():
    f = open('WORKER_NAME.%d' % PID, 'w')
f.write('Delete this to end WORKER_NAME gracefully')
f.close()
How to correctly shut down Python RQ worker processes dynamically?