Minimal code example below. Invoke with argument fork, forkserver or spawn. fork will work. forkserver and spawn will both raise the above error. All three variants work with Python 3.11.4.
I believe that the source of this regression is 34ef75d which adds the attribute is_fork_ctx to multiprocessing.Lock() but doesn't update the pickle methods (__getstate__() and __setstate__()) so after being serialised and deserialised, the Lock() object looses that attribute.
The following patch, adding is_fork_ctx to the pickle methods, makes the above work again.
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py
index 2328d33212..9c5c2aada6 100644
--- a/Lib/multiprocessing/synchronize.py+++ b/Lib/multiprocessing/synchronize.py@@ -109,10 +109,11 @@ def __getstate__(self):
'not supported. Please use the same context to create '
'multiprocessing objects and Process.')
h = sl.handle
- return (h, sl.kind, sl.maxvalue, sl.name)+ return (h, sl.kind, sl.maxvalue, sl.name, self.is_fork_ctx)
def __setstate__(self, state):
- self._semlock = _multiprocessing.SemLock._rebuild(*state)+ self._semlock = _multiprocessing.SemLock._rebuild(*state[:4])+ self.is_fork_ctx = state[4]
util.debug('recreated blocker with handle %r' % state[0])
self._make_methods()
Just to add confirmation to what has already been documented here and to document for others using the gcloud cli and finding this in search, I'm on python3.11.5 as well (Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)]) and am encountering this error with the gcloud cli tools.
A search for the following error message brought me here:
$ gcloud storage cp gs://bucket/file ./ --verbosity debug
DEBUG: Running [gcloud.storage.cp] with arguments: [--verbosity: "debug", DESTINATION: "./", SOURCE:1: "['gs://bucket/file']"]
DEBUG: Starting new HTTPS connection (1): storage.googleapis.com:443
DEBUG: https://storage.googleapis.com:443 "GET /storage/v1/b/bucket/o/data%2Ffile?alt=json&projection=noAcl HTTP/1.1" 200 896
Copying gs://bucket/file to file://./file
INFO: Using high CPU count, single-file workload config.
⠛ERROR: gcloud crashed (AttributeError): 'Lock' object has no attribute 'is_fork_ctx'
This happens regardless of which gcloud version I upgrade or downgrade to:
$ gcloud version
Google Cloud SDK 444.0.0
beta 2023.08.22
bq 2.0.97
core 2023.08.22
gcloud-crc32c 1.0.0
gsutil 5.25
And I can successfully execute the command if I tell gcloud to use an older python version before 3.11.5, e.g.:
It doesn't seem like a fix has been released for Mac yet. I'm still hitting this issue after running brew upgrade since it's still using python 3.11.5. I did confirm the workaround provided by @carbocation works correctly.
I can confirm that the problem no longer occurs with python 3.11.6 (tested with Google Cloud SDK 446.0.1 on MacOS 13.4). I had the issue with python 3.11.5
Activity
terryjreedy commented on Aug 26, 2023
@pitrou
albanD commented on Aug 28, 2023
Sorry about that, proposed a fix at #108568
carbocation commented on Aug 30, 2023
Just to add confirmation to what has already been documented here and to document for others using the gcloud cli and finding this in search, I'm on python3.11.5 as well (Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)]) and am encountering this error with the gcloud cli tools.
A search for the following error message brought me here:
This happens regardless of which gcloud version I upgrade or downgrade to:
And I can successfully execute the command if I tell gcloud to use an older python version before 3.11.5, e.g.:
$ CLOUDSDK_PYTHON=python3.10 gcloud storage cp gs://bucket/file ./ # (executes just fine)gh-108520: Fix bad fork detection in nested multiprocessing use case (#…
pythongh-108520: Fix bad fork detection in nested multiprocessing use…
Merge branch 'main' into icompexc
[3.11] gh-108520: Fix bad fork detection in nested multiprocessing us…
[3.12] gh-108520: Fix bad fork detection in nested multiprocessing us…
bwoodsend commented on Sep 2, 2023
The fix appears to be merged and backported. Shouldn't this be closed?
pitrou commented on Sep 2, 2023
Hmm, interesting. I thought that the auto-merge feature would also auto-close the issue, but it didn't.
samos123 commented on Sep 16, 2023
It doesn't seem like a fix has been released for Mac yet. I'm still hitting this issue after running brew upgrade since it's still using python 3.11.5. I did confirm the workaround provided by @carbocation works correctly.
bwoodsend commented on Sep 16, 2023
Correct, the fix version will be 3.11.6 which doesn't exist yet.
carbocation commented on Oct 3, 2023
looks like python3.11.6 was released today. I haven't tested the fix since I'm waiting for brew to support it (to keep my installations manageable).
nfonrose commented on Oct 15, 2023
I can confirm that the problem no longer occurs with python 3.11.6 (tested with Google Cloud SDK 446.0.1 on MacOS 13.4). I had the issue with python 3.11.5