summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-01-28 20:58:00 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-01-28 20:58:00 (GMT)
commitaf3d627022dcd0948610228b231106a198ed7bd8 (patch)
treea62fb34696d41725a4ab0e18c2d5e42c4d76091f
parent7a28447d4cd2ad768a1152725cce17d7c14b96c9 (diff)
downloadcpython-af3d627022dcd0948610228b231106a198ed7bd8.zip
cpython-af3d627022dcd0948610228b231106a198ed7bd8.tar.gz
cpython-af3d627022dcd0948610228b231106a198ed7bd8.tar.bz2
Use the thread lock's context manager instead of a try/finally statement.
-rw-r--r--Lib/_strptime.py5
1 files changed, 1 insertions, 4 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index baafe9a..5ea59ed 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -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" %