timeval: Import ctypes Python library within a try statement.
authorRyan Wilson <wryan@nicira.com>
Sat, 31 May 2014 00:36:46 +0000 (17:36 -0700)
committerAlex Wang <alexw@nicira.com>
Sat, 31 May 2014 00:37:10 +0000 (17:37 -0700)
Older versions of Python do not have ctypes as a default installed
package. This patch puts the 'import ctypes' statement inside a try
statement.

This fixes a bug introduced by commit 8396f (timeval: Use monotonic
time in OVS Python timeval library).

Signed-off-by: Ryan Wilson <wryan@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
python/ovs/timeval.py

index f2681ac..4463e87 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import ctypes
-import sys
 import time
 
 LIBRT = 'librt.so.1'
 CLOCK_MONOTONIC = 1
 
-class timespec(ctypes.Structure):
-    _fields_ = [
-        ('tv_sec', ctypes.c_long),
-        ('tv_nsec', ctypes.c_long),
-    ]
-
 try:
+    import ctypes
+
+    class timespec(ctypes.Structure):
+        _fields_ = [
+            ('tv_sec', ctypes.c_long),
+            ('tv_nsec', ctypes.c_long),
+        ]
+
     librt = ctypes.CDLL(LIBRT)
     clock_gettime = librt.clock_gettime
     clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]