fix lockutils.lock() to make it thread-safe

lockutils.lock() is currenctly safe when used with greenthreads, but it is not
safe when used with classic threads. This change uses a lock to protect
_semaphores dictionary.

Change-Id: Ia18e6e9f9a1353640729ac57d7225c660159cd55
Closes-Bug: 1065529
Adjust import order according to PEP8 imports rule

This patch just adjust import order to follow PEP8 imports rule.
See http://www.python.org/dev/peps/pep-0008/#imports
Imports should be grouped in the following order:

    standard library imports
    related third party imports
    local application/library specific imports

Change-Id: I6d92e9eda72d83cbf940b7699268f884bd4045c1
Merge "Adjust import order according to PEP8 imports rule"
Merge "fix lockutils.lock() to make it thread-safe"