[Truffle] Factor out releasing and acquiring the GIL.