Skip to content

Commit 1081bff

Browse files
Cleanup.
1 parent c7bd567 commit 1081bff

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

Lib/test/test_xpickle.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def setUpClass(cls):
104104
if not have_python_version(cls.py_version):
105105
py_version_str = ".".join(map(str, cls.py_version))
106106
raise unittest.SkipTest(f'Python {py_version_str} not available')
107-
cls.addClassCleanup(cls.close_worker)
107+
cls.addClassCleanup(cls.finish_worker)
108108
# Override the default pickle protocol to match what xpickle worker
109109
# will be running.
110110
highest_protocol = highest_proto_for_py_version(cls.py_version)
@@ -114,7 +114,7 @@ def setUpClass(cls):
114114
highest_protocol))
115115

116116
@classmethod
117-
def start_worker(cls):
117+
def start_worker(cls, python):
118118
target = os.path.join(os.path.dirname(__file__), 'xpickle_worker.py')
119119
worker = subprocess.Popen([*python, target],
120120
stdin=subprocess.PIPE,
@@ -123,9 +123,10 @@ def start_worker(cls):
123123
# For windows bpo-17023.
124124
shell=is_windows)
125125
cls.worker = worker
126+
return worker
126127

127128
@classmethod
128-
def close_worker(cls):
129+
def finish_worker(cls):
129130
worker = cls.worker
130131
if worker is None:
131132
return
@@ -149,14 +150,7 @@ def send_to_worker(cls, python, data):
149150
"""
150151
worker = cls.worker
151152
if worker is None:
152-
target = os.path.join(os.path.dirname(__file__), 'xpickle_worker.py')
153-
worker = subprocess.Popen([*python, target],
154-
stdin=subprocess.PIPE,
155-
stdout=subprocess.PIPE,
156-
stderr=subprocess.PIPE,
157-
# For windows bpo-17023.
158-
shell=is_windows)
159-
cls.worker = worker
153+
worker = cls.start_worker(python)
160154

161155
try:
162156
worker.stdin.write(struct.pack('!i', len(data)) + data)
@@ -179,7 +173,7 @@ def send_to_worker(cls, python, data):
179173
_, stderr = worker.communicate()
180174
raise RuntimeError(stderr)
181175
except:
182-
cls.close_worker()
176+
cls.finish_worker()
183177
raise
184178

185179
def dumps(self, arg, proto=0, **kwargs):

0 commit comments

Comments
 (0)