FAQ
Hi,

I've recently reinstalled Python 2.6 (from DMG) on my Mac, and I am
running into very strage errors. Namely, logging seems to be badly
broken. When I open the interpreter through Django's manage.py shell
and try to use logging, I get the following error:
logging.critical('ala')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py", line 1416, in critical
root.critical(*((msg,)+args), **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py", line 1074, in critical
self._log(CRITICAL, msg, args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py", line 1142, in _log
record = self.makeRecord(self.name, level, fn, lno, msg, args,
exc_info, func, extra)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py", line 1117, in makeRecord
rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py", line 272, in __init__
from multiprocessing import current_process
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/multiprocessing/__init__.py", line 64, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/multiprocessing/util.py", line 121, in <module>
_afterfork_registry = weakref.WeakValueDictionary()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/weakref.py", line 51, in __init__
UserDict.UserDict.__init__(self, *args, **kw)
TypeError: unbound method __init__() must be called with UserDict
instance as first argument (got WeakValueDictionary instance instead)

I was able to silence the error (and be able to work normally) by
making UserDict.UserDict inherit from object.

Any ideas what is causing the error? Before I updated Python
everything was fine. Am I breaking a lot of things by making
UserDict.UserDict a new style class?

Thanks in advance for any insight.

-- Ryszard Szopa

Search Discussions

  • Peter Otten at Jul 23, 2009 at 9:29 am

    Ryszard Szopa wrote:

    Hi,

    I've recently reinstalled Python 2.6 (from DMG) on my Mac, and I am
    running into very strage errors. Namely, logging seems to be badly
    broken. When I open the interpreter through Django's manage.py shell
    and try to use logging, I get the following error:
    logging.critical('ala')
    ------------------------------------------------------------
    Traceback (most recent call last):
    File "<ipython console>", line 1, in <module>
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/logging/__init__.py", line 1416, in critical
    root.critical(*((msg,)+args), **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/logging/__init__.py", line 1074, in critical
    self._log(CRITICAL, msg, args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/logging/__init__.py", line 1142, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args,
    exc_info, func, extra)
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/logging/__init__.py", line 1117, in makeRecord
    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/logging/__init__.py", line 272, in __init__
    from multiprocessing import current_process
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/multiprocessing/__init__.py", line 64, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/multiprocessing/util.py", line 121, in <module>
    _afterfork_registry = weakref.WeakValueDictionary()
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
    python2.6/weakref.py", line 51, in __init__
    UserDict.UserDict.__init__(self, *args, **kw)
    TypeError: unbound method __init__() must be called with UserDict
    instance as first argument (got WeakValueDictionary instance instead)

    I was able to silence the error (and be able to work normally) by
    making UserDict.UserDict inherit from object.

    Any ideas what is causing the error? Before I updated Python
    everything was fine. Am I breaking a lot of things by making
    UserDict.UserDict a new style class?

    Thanks in advance for any insight.

    -- Ryszard Szopa
    I have a hunch that you are triggering a reload() somewhere. Example:

    Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
    [GCC 4.3.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import weakref
    weakref.WeakValueDictionary()
    <WeakValueDictionary at 140598938447312>
    import UserDict
    reload(UserDict)
    <module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'>
    weakref.WeakValueDictionary()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.6/weakref.py", line 51, in __init__
    UserDict.UserDict.__init__(self, *args, **kw)
    TypeError: unbound method __init__() must be called with UserDict instance
    as first argument (got WeakValueDictionary instance instead)

    Try restarting the interpreter after any change to source files.

    Peter
  • Aahz at Jul 25, 2009 at 4:12 pm
    In article <h49ah5$hv3$02$1 at news.t-online.com>,
    Peter Otten wrote:
    I have a hunch that you are triggering a reload() somewhere. Example:

    Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
    [GCC 4.3.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import weakref
    weakref.WeakValueDictionary()
    <WeakValueDictionary at 140598938447312>
    import UserDict
    reload(UserDict)
    <module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'>
    weakref.WeakValueDictionary()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.6/weakref.py", line 51, in __init__
    UserDict.UserDict.__init__(self, *args, **kw)
    TypeError: unbound method __init__() must be called with UserDict instance
    as first argument (got WeakValueDictionary instance instead)
    Nice sleuthing! How did you figure that out?
    --
    Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

    "At Resolver we've found it useful to short-circuit any doubt and just
    refer to comments in code as 'lies'. :-)"
    --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22
  • Peter Otten at Jul 26, 2009 at 9:08 am

    Aahz wrote:

    In article <h49ah5$hv3$02$1 at news.t-online.com>,
    Peter Otten wrote:
    I have a hunch that you are triggering a reload() somewhere. Example:

    Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
    [GCC 4.3.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import weakref
    weakref.WeakValueDictionary()
    <WeakValueDictionary at 140598938447312>
    import UserDict
    reload(UserDict)
    <module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'>
    weakref.WeakValueDictionary()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.6/weakref.py", line 51, in __init__
    UserDict.UserDict.__init__(self, *args, **kw)
    TypeError: unbound method __init__() must be called with UserDict instance
    as first argument (got WeakValueDictionary instance instead)
    Nice sleuthing! How did you figure that out?
    Roughly:

    - The poster's description/remedy makes no sense (to me); have a look at the
    traceback.
    - Nothing suspicious except the actual error message. Isn't
    WeakValueDictionary a UserDict? Verify.
    - There must be two different UserDict classes. This can happen to an
    unsuspecting user by importing the main script or by doing a reload().
    UserDict is unlikely to be the main script, and web frameworks (django was
    mentioned) often use a reload mechanism to avoid frequent server restarts.
    - Reproduce the error.

    Peter

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 23, '09 at 9:08a
activeJul 26, '09 at 9:08a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2018 Grokbase