[Patches] [ python-Patches-766910 ] fix one or two bugs in trace.py

SourceForge.net noreply@sourceforge.net
Sun, 06 Jul 2003 18:46:30 -0700


Patches item #766910, was opened at 2003-07-07 01:46
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=766910&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Zooko O'Whielacronx (zooko)
Assigned to: Nobody/Anonymous (nobody)
Summary: fix one or two bugs in trace.py

Initial Comment:
There is one bug and one maybe-bug in creation of the
coverage file directory in trace.py.

The maybe-bug is that it doesn't attempt to create the
directory if it got the directory name from the name of
the .py file (instead of getting the directory name
from the --coverdir command line option).

Normally the directory will already exist, but if you
are writing out coverage files from a stored report
(or, I suppose, if someone deleted the directory after
the modules were loaded but before you wrote out the
report), then it won't.  This patch makes it so that it
always attempts to create the directory before
attempting to write files into it.  The patch also adds
a statement to that effect to the "--help" usage info.

The other bug is that it attempts to create a directory
with:

                if not os.path.exists(dir):
                    os.makedirs(dir)

, which is a race condition that will very rarely raise
a spurious exception ("File exists:") if two threads or
processes execute it at the same time.

The fix provided in this patch is to copy from my
pyutil project [1] a utility function that works around
this race condition and invoke that function.  On
request I'll provide a slimmed-down version of that
function, since we don't use all of its options in
trace.py.

This patch hasn't been tested at ALL.  In fact, I
haven't tested trace.py in general since before it
moved from Tools/scripts to Lib/.  As this patch ought
to go into Python 2.3, it ought to be tested, and I
promise to do so soon.

[1] http://sf.net/projects/pyutil


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=766910&group_id=5470