You might want to wrap that in a try/finally. e.g.

```
try:
    pin_this_thread()

    ...
finally:
    unpin_this_thread()
```