[Patches] [ python-Patches-922881 ] Patch for substantial startup time reduction

SourceForge.net noreply at sourceforge.net
Thu Mar 25 15:37:40 EST 2004


Patches item #922881, was opened at 2004-03-24 22:35
Message generated for change (Comment added) made by mondragon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=922881&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
>Resolution: Rejected
>Priority: 1
Submitted By: Nick Bastin (mondragon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Patch for substantial startup time reduction

Initial Comment:
This patch puts the delayed import of linecache back
into warnings.py, but protects it with a check against
the import lock being held by someone else.  This
results in regaining 50% of the launch speed that we
lost moving from 2.2.2 to 2.3.

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

>Comment By: Nick Bastin (mondragon)
Date: 2004-03-25 15:37

Message:
Logged In: YES 
user_id=430343

Arg - this only works in cvs.  In the installed version it doesn't make any 
difference.

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

Comment By: Nick Bastin (mondragon)
Date: 2004-03-25 15:07

Message:
Logged In: YES 
user_id=430343

Hopefully the last patch - whitespace screwed up in the last one.

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

Comment By: Nick Bastin (mondragon)
Date: 2004-03-25 13:07

Message:
Logged In: YES 
user_id=430343

Apparently the file didn't stick last time.  Lets try it again.

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

Comment By: Nick Bastin (mondragon)
Date: 2004-03-25 11:54

Message:
Logged In: YES 
user_id=430343

I've attached a new patch which corrects the multiple import
lock checks, and uses a global binding instead of the static
mutable default arg hack.. :-)

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

Comment By: Nick Bastin (mondragon)
Date: 2004-03-25 10:34

Message:
Logged In: YES 
user_id=430343

Yes, Jim's patch fixes the obvious problem...that's what I get for
writing code after a long day at PyCon.. :-)

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

Comment By: Jim Jewett (jimjjewett)
Date: 2004-03-25 10:13

Message:
Logged In: YES 
user_id=764593

It isn't letting me a attach a file just now, so I'll paste.

# Assumes that imp is imported at the top instead of 
# linecache, as in the original patch.

def formatwarning(message, category, filename, lineno,
                  linec = []):
    """Function to format a warning the standard way."""
    s =  "%s:%s: %s: %s\n" % (filename, lineno, category.
__name__, message)
    if not linec:
        if imp.lock_held():
            # Somebody else is holding the import lock.  To avoid  
            # a deadlock we just return the string so in worst 
            # case the user can look it up themselves.  Sorry.
            return s
        else:
            import linecache
            linec.append(linecache.getline)
    line = linec[0](filename, lineno).strip()
    if line:
        s = s + "  " + line + "\n"
    return s


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

Comment By: Jim Jewett (jimjjewett)
Date: 2004-03-25 10:10

Message:
Logged In: YES 
user_id=764593

You only need to import linecache once; after that, it 
shouldn't matter whether the lock is held.

You can track whether it was loaded with either a global or a 
mutable default value, but I'm not sure how unacceptable the 
style would be.  The warningupdate files shows a 
formatwarning with the mutable default variant.




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

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



More information about the Patches mailing list