Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Closed
Description
Bug report
Calling theclear
method on ashelve.Shelf
object takes a very long time on databases that have thousands of entries.
It can be seen in this script, which creates a database with 10,000 entries and immediately clears it.
importosimportshelveimporttempfilewithtempfile.TemporaryDirectory()astempdir:filename=os.path.join(tempdir,"test-shelf")withshelve.open(filename)asdb:items= {str(x):xforxinrange(10000)}db.update(items)db.clear()print("ok")
On my M2 Mac Mini, this script takes about 2.1 seconds.
james@iris ~ % time python shelve-clear-test.pyokpython shelve-clear-test.py 1.18s user 0.92s system 99% cpu 2.100 total
On a Debian VPS:
james@asteroid:~$ time python3 shelve-clear-test.py okreal0m43.665suser0m34.330ssys0m9.107s
Your environment
- CPython versions tested on
- 3.11.2
- 3.11.4
- cpython/main branch
- Operating system and architecture
- macOS/arm64 13.4.1
- Debian/x86_64 12.1