It's not actually locking, it's just instantiating a lock object inside the module. The lock is actually acquired/released internally by oauth2_client
; you don't need to manage it yourself. You can see this by looking at the source code, here: https://github.com/GoogleCloudPlatform/gsutil/blob/master/gslib/third_party/oauth2_plugin/oauth2_client.py
In fact, based on the source code linked above, you should be able to simply call oauth2_client.InitializeMultiprocessingVariables()
instead of the try/except
block, since that is ultimately doing almost the exact same thing.