[Yum-devel] Re: threading problem in config.py

Menno Smits menno-yum at freshfoo.com
Thu Mar 23 01:19:08 UTC 2006


Dan Williams wrote:
>> Specifically Paul, Menno - Any suggestions on things I should look at?
> 
> The specific problem is that installroot is a class attribute on
> EarlyConfig rather than an instance attribute , which means that it is
> the same across all threads.  That in itself is OK, but the problem
> happens in config.py::readMainConfig() when this gets run:
> 
>     EarlyConf.installroot.default = root
> 
> 'root' is specific to the thread, yet the object EarlyConf.installroot
> is shared between threads, it being a class attribute initialized on
> module load.  The last thread to set installroot.default wins...
> 
> It would appear that this isn't unique to EarlyConfig either, since all
> the other BaseConfig subclasses use class attributes for options, rather
> than instance attributes.

The option definitions (which include the default value) are stored in 
the classes. The actual option values read are stored in the instances. 
The class-wide default default is used if no value was set in the 
configuration file so when the default changes each instance sees this 
change.

Potential Fix 1
---------------
Have BaseConfig.populate() fill in the default value from the option if 
there's no value from in the INI file and have Option.__get__() just 
always return this value instead of referring to the class-wide default.

This should work and is quite simple. The reason I didn't do this in the 
first place was to conserve a little bit of memory.

Potential Fix 2
----------------
Do something like:

     earlyconf = EarlyConf()
     earlyconf.installroot = root

instead of:

     EarlyConf.installroot.default = root
     earlyconf = EarlyConf()

in readMainConfig(). That way the value in a specific instance is 
modified instead of the default of for all instances. One thing to watch 
is that the correct value is propagated into yumconf too. You may need 
to assign to the installroot attribute of yumconf too.

I don't have time to test this right now because I'm at work but this 
should point you in the right direction. I prefer fix 1 over fix 2. It's 
cleaner and fixes the threading problem for all options.

Let me know how you go.

Menno










More information about the Yum-devel mailing list