This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Patch for substantial startup time reduction
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: jimjjewett, nbastin
Priority: low Keywords: patch

Created on 2004-03-25 03:35 by nbastin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
warnings.patch nbastin, 2004-03-25 20:07
Messages (9)
msg45656 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 03:35
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.
msg45657 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-03-25 15:10
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.


msg45658 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-03-25 15:13
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
msg45659 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 15:34
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.. :-)
msg45660 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 16:54
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.. :-)
msg45661 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 18:07
Logged In: YES 
user_id=430343

Apparently the file didn't stick last time.  Lets try it again.
msg45662 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 20:07
Logged In: YES 
user_id=430343

Hopefully the last patch - whitespace screwed up in the last one.
msg45663 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-25 20:37
Logged In: YES 
user_id=430343

Arg - this only works in cvs.  In the installed version it doesn't make any 
difference.
msg45664 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-03-30 14:56
Logged In: YES 
user_id=764593

Does that still make it worth applying for 2.4?
It isn't really a good 2.3 candidate anyhow, since "slow" isn't a 
bug.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40074
2004-03-25 03:35:24nbastincreate