Ensure proper cleanup and GIL release inside async handler