The GIL doesn't switch threads. The GIL is a mutex that prevents multiple threads from executing bytecode at the same time. As such, to prevent thread switching you need to look elsewhere.
You could call sys.setcheckinterval()
with a really large value to prevent switching while your code is being profiled.
Whenever you call sys.setcheckinterval(count)
the current 'counter' is reset to the new value, so as soon as you call it no thread switch is allowed for at least count
bytecode instructions.