Fix for Issue #3255: ImportError Undefined symbol: PyGILState_Release

We need to enclose all calls to python API functions which are available only for a multi-threaded python with #ifdef WITH_THREAD.