mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +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
|
||||
|
||||
# Check first outside the lock.
|
||||
if var in vars and vars[var] is not None:
|
||||
if vars.get(var) is not None:
|
||||
return
|
||||
try:
|
||||
lock.acquire()
|
||||
# Check again inside the lock.
|
||||
if var in vars and vars[var] is not None:
|
||||
if vars.get(var) is not None:
|
||||
return
|
||||
vars[var] = initializer()
|
||||
finally:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue