Skip to content

Commit 12069d0

Browse files
author
Release Manager
committed
gh-36437: src/sage/parallel/map_reduce.py: replace tmp_dir() Standard `tempfile.TemporaryDirectory()` replacement for `tmp_dir()` and fix a deprecation warning while we're at it. Issue: #36322 URL: #36437 Reported by: Michael Orlitzky Reviewer(s): Marc Mezzarobba
2 parents 4a60001 + ee0d8ef commit 12069d0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/sage/parallel/map_reduce.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@
293293
The profiling is activated by the ``profile`` parameter. The value provided
294294
should be a prefix (including a possible directory) for the profile dump::
295295
296-
sage: prof = tmp_dir('RESetMR_profile') + 'profcomp'
297-
sage: res = S.run(profile=prof) # random
296+
sage: import tempfile
297+
sage: d = tempfile.TemporaryDirectory(prefix="RESetMR_profile")
298+
sage: res = S.run(profile=d.name) # random
298299
[RESetMapReduceWorker-1:58] (20:00:41.444) Profiling in
299300
/home/user/.sage/temp/.../32414/RESetMR_profilewRCRAx/profcomp1
300301
...
@@ -309,7 +310,7 @@
309310
:class:`cProfile.Profile` for more details::
310311
311312
sage: import cProfile, pstats
312-
sage: st = pstats.Stats(prof+'0')
313+
sage: st = pstats.Stats(d.name+'0')
313314
sage: st.strip_dirs().sort_stats('cumulative').print_stats() # random
314315
...
315316
Ordered by: cumulative time
@@ -320,6 +321,11 @@
320321
...
321322
<pstats.Stats instance at 0x7fedea40c6c8>
322323
324+
Like a good neighbor we clean up our temporary directory as soon as
325+
possible::
326+
327+
sage: d.cleanup()
328+
323329
.. SEEALSO::
324330
325331
`The Python Profilers <https://docs.python.org/2/library/profile.html>`_
@@ -1713,7 +1719,7 @@ def run(self):
17131719
PROFILER.runcall(self.run_myself)
17141720

17151721
output = profile + str(self._iproc)
1716-
logger.warn(f"Profiling in {output} ...")
1722+
logger.warning(f"Profiling in {output} ...")
17171723
PROFILER.dump_stats(output)
17181724
else:
17191725
self.run_myself()

0 commit comments

Comments
 (0)