[Sugar-devel] [PATCH] Time out on registration process to prevent indefinite UI hang (SL#2289)

Tomeu Vizoso tomeu at sugarlabs.org
Wed Sep 8 05:00:13 EDT 2010


On Tue, Sep 7, 2010 at 19:44, Dipankar Patro <dipankar at seeta.in> wrote:
> Registration with the school server is currently done synchronously.
> To prevent the UI from hanging indefinitely, if the school server is reachable
> but unresponsive, we add an explicit timeout.
> ---
>  src/jarabe/desktop/schoolserver.py |   19 ++++++++++++++++---
>  1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
> index 62519df..6a96077 100644
> --- a/src/jarabe/desktop/schoolserver.py
> +++ b/src/jarabe/desktop/schoolserver.py
> @@ -16,7 +16,8 @@
>
>  import logging
>  from gettext import gettext as _
> -from xmlrpclib import ServerProxy, Error
> +import httplib
> +import xmlrpclib
>  import socket
>  import os
>  import string
> @@ -30,6 +31,7 @@ from sugar import env
>  from sugar.profile import get_profile
>
>  REGISTER_URL = 'http://schoolserver:8080/'
> +REGISTER_TIMEOUT = 10
>
>  def generate_serial_number():
>     """  Generates a serial number based on 3 random uppercase letters
> @@ -76,6 +78,17 @@ def store_identifiers(serial_number, uuid, backup_url):
>  class RegisterError(Exception):
>     pass
>
> +class TimeoutHTTP(httplib.HTTP):

http://docs.python.org/library/httplib.html says:

Note

The public interface for this module changed substantially in Python
2.0. The HTTP class is retained only for backward compatibility with
1.5.2. It should not be used in new code. Refer to the online
docstrings for usage.

Have you considered using the non-deprecated APIs?

> +   def __init__(self, host='', port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
> +        if port == 0:
> +            port = None
> +        self._setup(self._connection_class(host, port, strict, timeout))

We should never use private and undocumented methods. If this is
indeed the only way to achieve what we want, then we should put a big
warning in the code that points to a ticket in trac because that would
be indeed a bug in Sugar.

Regards,

Tomeu

> +class TimeoutTransport(xmlrpclib.Transport):
> +       def make_connection(self, host):
> +        host, extra_headers, x509 = self.get_host_info(host)
> +        return TimeoutHTTP(host, timeout = REGISTER_TIMEOUT)
> +
>  def register_laptop(url=REGISTER_URL):
>
>     profile = get_profile()
> @@ -95,10 +108,10 @@ def register_laptop(url=REGISTER_URL):
>
>     nick = client.get_string('/desktop/sugar/user/nick')
>
> -    server = ServerProxy(url)
> +    server = xmlrpclib.ServerProxy(url, TimeoutTransport())
>     try:
>         data = server.register(sn, nick, uuid_, profile.pubkey)
> -    except (Error, socket.error):
> +    except (xmlrpclib.Error, socket.error):
>         logging.exception('Registration: cannot connect to server')
>         raise RegisterError(_('Cannot connect to the server.'))
>
> --
> 1.7.0.4
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


More information about the Sugar-devel mailing list