Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit602de0c

Browse files
committed
Begin multiprocessing misadventure
There is no per-instance state involved in USE_SHELL, so picklingis far less directly relevant than usual to multiprocessing: thespawn and forkserver methods will not preserve a subsequentlychanged attribute value unless side effects of loading a module (orother unpickling of a function or its arguments that are submittedto run on a worker subprocess) causes it to run again; the forkmethod will.This will be (automatically) the same with any combination ofmetaclasses, properties, and custom descriptors as in the morestraightforward case of a simple class attribute. Subtleties arisein the code that uses GitPython and multiprocessing, but should notarise unintentionally from the change in implementation of USE_SHELLdone to add deprecation warnings, except possibly with respect towhether warnings will be repeated in worker processes, which isless important than whether the actual state is preserved.
1 parentbf13888 commit602de0c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

‎test/deprecation/test_cmd_git.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
access are not inadvertently broken by mechanisms introduced to issue the warnings.
77
"""
88

9+
fromconcurrent.futuresimportProcessPoolExecutor
910
importcontextlib
1011
importsys
1112
fromtypingimportGenerator
@@ -36,7 +37,7 @@ def _suppress_deprecation_warning() -> Generator[None, None, None]:
3637

3738

3839
@pytest.fixture
39-
deftry_restore_use_shell_state()->Generator[None,None,None]:
40+
defrestore_use_shell_state()->Generator[None,None,None]:
4041
"""Fixture to attempt to restore state associated with the ``USE_SHELL`` attribute.
4142
4243
This is used to decrease the likelihood of state changes leaking out and affecting
@@ -142,7 +143,7 @@ def _assert_use_shell_full_results(
142143
assertrecheck_message.startswith(_USE_SHELL_DEPRECATED_FRAGMENT)
143144

144145

145-
deftest_use_shell_set_and_get_on_class(try_restore_use_shell_state:None)->None:
146+
deftest_use_shell_set_and_get_on_class(restore_use_shell_state:None)->None:
146147
"""USE_SHELL can be set and re-read as a class attribute, always warning."""
147148
withpytest.deprecated_call()assetting:
148149
Git.USE_SHELL=True
@@ -163,7 +164,7 @@ def test_use_shell_set_and_get_on_class(try_restore_use_shell_state: None) -> No
163164
)
164165

165166

166-
deftest_use_shell_set_on_class_get_on_instance(try_restore_use_shell_state:None)->None:
167+
deftest_use_shell_set_on_class_get_on_instance(restore_use_shell_state:None)->None:
167168
"""USE_SHELL can be set on the class and read on an instance, always warning.
168169
169170
This is like test_use_shell_set_and_get_on_class but it performs reads on an
@@ -196,14 +197,31 @@ class (or an instance) is needed first before a read on an instance (or the clas
196197
@pytest.mark.parametrize("value", [False,True])
197198
deftest_use_shell_cannot_set_on_instance(
198199
value:bool,
199-
try_restore_use_shell_state:None,# In case of a bug where it does set USE_SHELL.
200+
restore_use_shell_state:None,# In case of a bug where it does set USE_SHELL.
200201
)->None:
201202
instance=Git()
202203
withpytest.raises(AttributeError):
203204
instance.USE_SHELL=value
204205

205206

206-
# FIXME: Test behavior with multiprocessing (the attribute needs to pickle properly).
207+
def_check_use_shell_in_worker(value:bool)->None:
208+
# USE_SHELL should have the value set in the parent before starting the worker.
209+
assertGit.USE_SHELLisvalue
210+
211+
# FIXME: Check that mutation still works and raises the warning.
212+
213+
214+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
215+
@pytest.mark.parametrize("value", [False,True])
216+
deftest_use_shell_preserved_in_multiprocessing(
217+
value:bool,
218+
restore_use_shell_state:None,
219+
)->None:
220+
"""The USE_SHELL class attribute pickles accurately for multiprocessing."""
221+
Git.USE_SHELL=value
222+
withProcessPoolExecutor(max_workers=1)asexecutor:
223+
# Calling result() marshals any exception back to this process and raises it.
224+
executor.submit(_check_use_shell_in_worker,value).result()
207225

208226

209227
_EXPECTED_DIR_SUBSET= {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp