[PATCH 1/3] Initialize threading when the module is imported.

David Shea dshea at redhat.com
Mon Aug 25 13:38:13 UTC 2014


On 08/22/2014 06:31 PM, Brian C. Lane wrote:
> On Fri, Aug 22, 2014 at 05:19:33PM -0400, David Shea wrote:
>> This way threadMgr is initialized the first time the module is loaded
>> and is never set to None.
>> ---
>>   anaconda              | 8 +++-----
>>   pyanaconda/threads.py | 7 +++----
>>   2 files changed, 6 insertions(+), 9 deletions(-)
>>
>> diff --git a/anaconda b/anaconda
>> index 7fb9370..1cffff7 100755
>> --- a/anaconda
>> +++ b/anaconda
>> @@ -903,11 +903,9 @@ if __name__ == "__main__":
>>       setupPythonUpdates()
>>       setupPythonPath()
>>   
>> -    # init threading before Gtk can do anything and before we start using threads
>> -    # initThreading initializes the threadMgr instance, import it afterwards
>> -    from pyanaconda.threads import initThreading, AnacondaThread
>> -    initThreading()
>> -    from pyanaconda.threads import threadMgr
>> +    # Import and initialize threading before Gtk can do anything and before we
>> +    # start using threads.
>> +    from pyanaconda.threads import threadMgr, AnacondaThread
>>   
>>       import gettext
>>       _ = lambda x: gettext.ldgettext("anaconda", x)
>> diff --git a/pyanaconda/threads.py b/pyanaconda/threads.py
>> index eea1da6..7511195 100644
>> --- a/pyanaconda/threads.py
>> +++ b/pyanaconda/threads.py
>> @@ -234,13 +234,12 @@ class AnacondaThread(threading.Thread):
>>               threadMgr.remove(self.name)
>>               log.info("Thread Done: %s (%s)", self.name, self.ident)
>>   
>> -def initThreading():
>> +def _initThreading():
>>       """Set up threading for anaconda's use. This method must be called before
>>          any GTK or threading code is called, or else threads will only run when
>>          an event is triggered in the GTK main loop. And IT HAS TO BE CALLED IN
>>          THE MAIN THREAD.
>>       """
>> -    global threadMgr
>> -    threadMgr = ThreadManager()
>> +    return ThreadManager()
>>   
>> -threadMgr = None
>> +threadMgr = _initThreading()
>> -- 
>> 1.9.3
> I *think* this is ok, but wonder why it was done in anaconda before? Are
> there any other users of pyanaconda.thread that wouldn't want it
> initialized on import, like firstboot maybe?
>

Good point. initial-setup does use initThreading, and for a case like 
that it's probably best to leave it like it was, since it doesn't use 
anything else from the threads module. I'll drop this patch and try to 
figure out why threadMgr was None while initializing payloadMgr.


More information about the anaconda-patches mailing list