strange error when trying to log something

Peter Otten __peter__ at
Sun Jul 26 05:08:10 EDT 2009

Aahz wrote:

> In article <h49ah5$hv3$02$1 at>,
> Peter Otten  <__peter__ at> 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/", 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?


- The poster's description/remedy makes no sense (to me); have a look at the 
- 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.


More information about the Python-list mailing list