Script run through "bin/instance run" won't exit/terminate

I have a custom migration script (basically wrapper around the views of collective.exportimport) that does not terminate/exit properly. The script ends with a transaction.commit() then performs a few catalog queries for printing some migration stats. However the script never returns the control or not does it exit properly (even after two hours!). Anyone seen a similar behavior? Test with Plone 6.0.0a4.

I would add this at the begin of the script:

def print_traceback():
    for line in traceback.format_stack():
        print(line.strip())

# when killed or ctrl+c prompt the debugger instead of exit
def handler(signal, frame):
    print_traceback()
    pdb.set_trace()


signal.signal(signal.SIGTERM, handler)

and after a while you can press ctrl+C and see what happen. You can just comment pdb.set_trace() and take a look to the traceback.