pdb.Pdb().set_trace(frame)

def loop():
    while True:
        x = 'foo'
time.sleep(0.2)
if __name__ == '__main__':
    signal.signal(signal.SIGUSR1, handle_pdb)
print(os.getpid())
loop()
Attaching a process with pdb