Skip to content

Commit a8a26da

Browse files
committed
fix: only fix cProfile
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
1 parent 50dec2f commit a8a26da

File tree

3 files changed

+4
-43
lines changed

3 files changed

+4
-43
lines changed

Lib/profile.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,13 @@ def main():
604604
origin=progname)
605605
module = importlib.util.module_from_spec(spec)
606606
sys.modules['__main__'] = module
607-
globs = module.__dict__
608-
globs.update({
609-
'__spec__': None,
607+
globs = {
608+
'__spec__': spec,
610609
'__file__': spec.origin,
611610
'__name__': spec.name,
612611
'__package__': None,
613612
'__cached__': None,
614-
})
613+
}
615614
try:
616615
runctx(code, globs, None, options.outfile, options.sort)
617616
except BrokenPipeError as exc:

Lib/test/test_profile.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import pstats
55
import unittest
66
import os
7-
import subprocess
87
import warnings
98
from difflib import unified_diff
109
from io import StringIO
1110
from test.support.os_helper import TESTFN, unlink, temp_dir, change_cwd
12-
from test.support import script_helper, os_helper, SHORT_TIMEOUT
1311
from contextlib import contextmanager, redirect_stdout
1412

1513
# Suppress deprecation warning for profile module (PEP 799)
@@ -136,41 +134,6 @@ def test_output_file_when_changing_directory(self):
136134

137135
self.assertTrue(os.path.exists('out.pstats'))
138136

139-
@unittest.skipIf(sys.platform == 'win32',
140-
'Profiler with multiprocessing can not run on win32')
141-
def test_profile_multiprocessing(self):
142-
test_script = '''
143-
import multiprocessing
144-
def worker_proc(x):
145-
return x * 42
146-
147-
def main_proc():
148-
p = multiprocessing.Process(target=worker_proc, args=(10,))
149-
p.start()
150-
p.join()
151-
152-
if __name__ == "__main__":
153-
main_proc()
154-
'''
155-
with os_helper.temp_dir() as temp_dir:
156-
script = script_helper.make_script(
157-
temp_dir, 'test_profile_multiprocessing', test_script
158-
)
159-
with script_helper.spawn_python(
160-
"-m", self.profilermodule.__name__,
161-
script,
162-
stderr=subprocess.PIPE,
163-
text=True
164-
) as proc:
165-
proc.wait(timeout=SHORT_TIMEOUT)
166-
stdout = proc.stdout.read()
167-
stderr = proc.stderr.read()
168-
169-
self.assertIn("main_proc", stdout)
170-
self.assertNotIn("Can't pickle", stderr)
171-
self.assertNotIn("ModuleSpec", stderr)
172-
self.assertEqual(proc.returncode, 0)
173-
174137

175138
def regenerate_expected_output(filename, cls):
176139
filename = filename.rstrip('co')
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Set ``__main__.__spec__`` to ``None`` when running a script with
2-
:mod:`profile` or :mod:`cProfile`
1+
Set ``__main__.__spec__`` to ``None`` when running a script with :mod:`cProfile`

0 commit comments

Comments
 (0)