[master][PATCH] Create the XklWrapper singleton in background

David Shea dshea at redhat.com
Fri Sep 13 13:53:20 UTC 2013


On 09/13/2013 08:08 AM, Vratislav Podzimek wrote:
> Creating the XklWrapper instance takes quite a lot of time (~4 seconds on a VM).
> Instead of doing when the first spoke needs it, we can create the instance in
> background as soon as the X server is started. Since it includes a lot of I/O
> operations, threading makes a real difference (at least 2 seconds on a VM). But
> the main advantage is that this long action happens before we show anything to
> user and not when some grey screen is shown.
> ---
>   anaconda                | 15 +++++++++++++++
>   pyanaconda/constants.py |  1 +
>   pyanaconda/keyboard.py  |  7 +++++--
>   3 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/anaconda b/anaconda
> index 3e745e3..8b0dfc9 100755
> --- a/anaconda
> +++ b/anaconda
> @@ -85,6 +85,19 @@ def startSpiceVDAgent():
>       else:
>           log.info("Started spice-vdagent.")
>   
> +def backgroundXklWrapperInitialize():
> +    """
> +    Create the XklWrapper singleton instance in a separate thread to save time
> +    when it's really needed.
> +
> +    """
> +
> +    from pyanaconda.constants import THREAD_XKL_WRAPPER_INIT
> +    from pyanaconda.keyboard import XklWrapper
> +    from pyanaconda.threads import threadMgr, AnacondaThread
> +
> +    threadMgr.add(AnacondaThread(name=THREAD_XKL_WRAPPER_INIT, target=XklWrapper.get_instance))
> +
>   def startMetacityWM():
>       childpid = os.fork()
>       if not childpid:
> @@ -144,6 +157,8 @@ def doExtraX11Actions(runres):
>   
>       startSpiceVDAgent()
>   
> +    backgroundXklWrapperInitialize()
> +
>   def setupPythonUpdates():
>       from distutils.sysconfig import get_python_lib
>       import gi.overrides
> diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
> index d4d8708..dfb9200 100644
> --- a/pyanaconda/constants.py
> +++ b/pyanaconda/constants.py
> @@ -117,6 +117,7 @@ THREAD_ISCSI_LOGIN = "AnaIscsiLoginThread"
>   THREAD_GEOLOCATION_REFRESH = "AnaGeolocationRefreshThread"
>   THREAD_DATE_TIME = "AnaDateTimeThread"
>   THREAD_TIME_INIT = "AnaTimeInitThread"
> +THREAD_XKL_WRAPPER_INIT = "AnaXklWrapperInitThread"
>   
>   # Geolocation constants
>   
> diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py
> index e5b7793..cf3f5d8 100644
> --- a/pyanaconda/keyboard.py
> +++ b/pyanaconda/keyboard.py
> @@ -38,6 +38,7 @@ import re
>   import shutil
>   import ctypes
>   import gettext
> +import threading
>   
>   from collections import namedtuple
>   
> @@ -363,11 +364,13 @@ class XklWrapper(object):
>       """
>   
>       _instance = None
> +    _instance_lock = threading.Lock()
>   
>       @staticmethod
>       def get_instance():
> -        if not XklWrapper._instance:
> -            XklWrapper._instance = XklWrapper()
> +        with XklWrapper._instance_lock:
> +            if not XklWrapper._instance:
> +                XklWrapper._instance = XklWrapper()
>   
>           return XklWrapper._instance
>   
Ack


More information about the anaconda-patches mailing list