import sys

### main body of code
### running in a single
### thread goes here

try:
    sys.setcheckinterval(sys.maxint)
    # statements in this block are
    # assured to run atomically
finally:
    sys.setcheckinterval(100)

### rest of code in the thread
### goes here
