Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use lock=False throughout stdlib and docs
  • Loading branch information
carljm committed Oct 9, 2022
commit 246d72ec556f83bceaf089a7a7f0a9ee9570149f
2 changes: 1 addition & 1 deletion Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ This example shows the various techniques::
# Do not cache this because old results
# can be out of date.

@cached_property
@cached_property(lock=False)
def location(self):
"Return the longitude/latitude coordinates of the station"
# Result only depends on the station_id
Expand Down
2 changes: 1 addition & 1 deletion Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ instance dictionary to function correctly:
class CP:
__slots__ = () # Eliminates the instance dict

@cached_property # Requires an instance dict
@cached_property(lock=False) # Requires an instance dict
def pi(self):
return 4 * sum((-1.0)**n / (2.0*n + 1.0)
for n in reversed(range(100_000)))
Expand Down
8 changes: 4 additions & 4 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,12 @@ def overlaps(self, other):
other.network_address in self or (
other.broadcast_address in self)))

@functools.cached_property
@functools.cached_property(lock=False)
def broadcast_address(self):
return self._address_class(int(self.network_address) |
int(self.hostmask))

@functools.cached_property
@functools.cached_property(lock=False)
def hostmask(self):
return self._address_class(int(self.netmask) ^ self._ALL_ONES)

Expand Down Expand Up @@ -1390,7 +1390,7 @@ def __init__(self, address):
self.netmask = self.network.netmask
self._prefixlen = self.network._prefixlen

@functools.cached_property
@functools.cached_property(lock=False)
def hostmask(self):
return self.network.hostmask

Expand Down Expand Up @@ -2094,7 +2094,7 @@ def __init__(self, address):
self.netmask = self.network.netmask
self._prefixlen = self.network._prefixlen

@functools.cached_property
@functools.cached_property(lock=False)
def hostmask(self):
return self.network.hostmask

Expand Down
2 changes: 1 addition & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def check(self):
traceback.print_exc()
sys.exit(1)

@functools.cached_property
@functools.cached_property(lock=False)
def _details(self):
import runpy
return runpy._get_module_details(self)
Expand Down
2 changes: 1 addition & 1 deletion Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ class uname_result(
except when needed.
"""

@functools.cached_property
@functools.cached_property(lock=False)
def processor(self):
return _unknown_as_blank(_Processor.get())

Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ class CachedCostItem:
def __init__(self):
self.lock = py_functools.RLock()

@py_functools.cached_property
@py_functools.cached_property(lock=False)
def cost(self):
"""The cost of the item."""
with self.lock:
Expand All @@ -2928,7 +2928,7 @@ def get_cost(self):
self._cost += 1
return self._cost

cached_cost = py_functools.cached_property(get_cost)
cached_cost = py_functools.cached_property(get_cost, lock=False)


class CachedCostItemWait:
Expand Down Expand Up @@ -2967,7 +2967,7 @@ class CachedCostItemWithSlots:
def __init__(self):
self._cost = 1

@py_functools.cached_property
@py_functools.cached_property(lock=False)
def cost(self):
raise RuntimeError('never called, slots not supported')

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ class TestModule(ZoneInfoTestBase):
def zoneinfo_data(self):
return ZONEINFO_DATA

@cached_property
@cached_property(lock=False)
def _UTC_bytes(self):
zone_file = self.zoneinfo_data.path_from_key("UTC")
with open(zone_file, "rb") as f:
Expand Down