]> granicus.if.org Git - python/commitdiff
Use the thread lock's context manager instead of a try/finally statement.
authorBrett Cannon <bcannon@gmail.com>
Sun, 28 Jan 2007 20:58:00 +0000 (20:58 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sun, 28 Jan 2007 20:58:00 +0000 (20:58 +0000)
Lib/_strptime.py

index baafe9aab5d9c9ade69e63d480aba54d3c2af95e..5ea59ed7be0dc8a7eb3a2815e0e5cb52652a2adc 100644 (file)
@@ -294,8 +294,7 @@ def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
 def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
     """Return a time struct based on the input string and the format string."""
     global _TimeRE_cache, _regex_cache
-    _cache_lock.acquire()
-    try:
+    with _cache_lock:
         time_re = _TimeRE_cache
         locale_time = time_re.locale_time
         if _getlang() != locale_time.lang:
@@ -320,8 +319,6 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
             except IndexError:
                 raise ValueError("stray %% in format '%s'" % format)
             _regex_cache[format] = format_regex
-    finally:
-        _cache_lock.release()
     found = format_regex.match(data_string)
     if not found:
         raise ValueError("time data %r does not match format %r" %