Properly handle GIL in input and output task