From e658fb3268ca192e5f329314bbb4fb3f62652e30 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 10 Jan 2016 12:52:25 -0500 Subject: A little clean up of the monkey-patch --- coverage/monkey.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'coverage/monkey.py') diff --git a/coverage/monkey.py b/coverage/monkey.py index 3f78d7dc..e7517bf6 100644 --- a/coverage/monkey.py +++ b/coverage/monkey.py @@ -33,6 +33,15 @@ class ProcessWithCoverage(klass): cov.save() +class Stowaway(object): + """An object to pickle, so when it is unpickled, it can apply the monkey-patch.""" + def __getstate__(self): + return {} + + def __setstate__(self, state_unused): + patch_multiprocessing() + + def patch_multiprocessing(): """Monkey-patch the multiprocessing module. @@ -55,7 +64,7 @@ def patch_multiprocessing(): # re-applies the monkey-patch. # Windows only spawns, so this is needed to keep Windows working. try: - from multiprocessing import spawn + from multiprocessing import spawn # pylint: disable=no-name-in-module original_get_preparation_data = spawn.get_preparation_data except (ImportError, AttributeError): pass @@ -69,12 +78,3 @@ def patch_multiprocessing(): spawn.get_preparation_data = get_preparation_data_with_stowaway setattr(multiprocessing, PATCHED_MARKER, True) - - -class Stowaway(object): - """An object to pickle, so when it is unpickled, it can apply the monkey-patch.""" - def __getstate__(self): - return {} - - def __setstate__(self, state): - patch_multiprocessing() -- cgit v1.2.1