Mercurial > hgrepos > Python > apps > py-cutils
comparison shasum.py @ 61:c9f9401abc0c
Use getattr when trying to get mmap.madvise()
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 09 Feb 2022 12:00:27 +0100 |
| parents | 21d2589c96b9 |
| children | c52e5f86b0ab |
comparison
equal
deleted
inserted
replaced
| 60:21d2589c96b9 | 61:c9f9401abc0c |
|---|---|
| 479 # Use mmap | 479 # Use mmap |
| 480 # | 480 # |
| 481 # NOTE: On Windows mmapped files with length 0 are not supported. | 481 # NOTE: On Windows mmapped files with length 0 are not supported. |
| 482 # So ensure to not call mmap.mmap() if the file size is 0. | 482 # So ensure to not call mmap.mmap() if the file size is 0. |
| 483 # | 483 # |
| 484 try: | 484 madvise = getattr(mmap.mmap, "madvise", None) |
| 485 madvise = mmap.mmap.madvise | |
| 486 except AttributeError: | |
| 487 madvise = None | |
| 488 if filesize < MAP_CHUNK_SIZE: | 485 if filesize < MAP_CHUNK_SIZE: |
| 489 mapsize = filesize | 486 mapsize = filesize |
| 490 else: | 487 else: |
| 491 mapsize = MAP_CHUNK_SIZE | 488 mapsize = MAP_CHUNK_SIZE |
| 492 mapoffset = 0 | 489 mapoffset = 0 |
