Skip to content

Commit

Permalink
sagemathgh-36437: src/sage/parallel/map_reduce.py: replace tmp_dir()
Browse files Browse the repository at this point in the history
    
Standard `tempfile.TemporaryDirectory()` replacement for `tmp_dir()` and
fix a deprecation warning while we're at it.

Issue: sagemath#36322
    
URL: sagemath#36437
Reported by: Michael Orlitzky
Reviewer(s): Marc Mezzarobba
  • Loading branch information
Release Manager committed Oct 15, 2023
2 parents e46ed3b + ee0d8ef commit ca57e87
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/sage/parallel/map_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@
The profiling is activated by the ``profile`` parameter. The value provided
should be a prefix (including a possible directory) for the profile dump::
sage: prof = tmp_dir('RESetMR_profile') + 'profcomp'
sage: res = S.run(profile=prof) # random
sage: import tempfile
sage: d = tempfile.TemporaryDirectory(prefix="RESetMR_profile")
sage: res = S.run(profile=d.name) # random
[RESetMapReduceWorker-1:58] (20:00:41.444) Profiling in
/home/user/.sage/temp/.../32414/RESetMR_profilewRCRAx/profcomp1
...
Expand All @@ -309,7 +310,7 @@
:class:`cProfile.Profile` for more details::
sage: import cProfile, pstats
sage: st = pstats.Stats(prof+'0')
sage: st = pstats.Stats(d.name+'0')
sage: st.strip_dirs().sort_stats('cumulative').print_stats() # random
...
Ordered by: cumulative time
Expand All @@ -320,6 +321,11 @@
...
<pstats.Stats instance at 0x7fedea40c6c8>
Like a good neighbor we clean up our temporary directory as soon as
possible::
sage: d.cleanup()
.. SEEALSO::
`The Python Profilers <https://docs.python.org/2/library/profile.html>`_
Expand Down Expand Up @@ -1713,7 +1719,7 @@ def run(self):
PROFILER.runcall(self.run_myself)

output = profile + str(self._iproc)
logger.warn(f"Profiling in {output} ...")
logger.warning(f"Profiling in {output} ...")
PROFILER.dump_stats(output)
else:
self.run_myself()
Expand Down

0 comments on commit ca57e87

Please sign in to comment.