mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
_once(): Simplified dict manipulation.
This commit is contained in:
parent
200788ce45
commit
fd0f0c9f02
1 changed files with 2 additions and 2 deletions
|
@ -101,12 +101,12 @@ def _once(var, initializer):
|
||||||
lock = _once_lock
|
lock = _once_lock
|
||||||
|
|
||||||
# Check first outside the lock.
|
# Check first outside the lock.
|
||||||
if var in vars and vars[var] is not None:
|
if vars.get(var) is not None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
# Check again inside the lock.
|
# Check again inside the lock.
|
||||||
if var in vars and vars[var] is not None:
|
if vars.get(var) is not None:
|
||||||
return
|
return
|
||||||
vars[var] = initializer()
|
vars[var] = initializer()
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue