Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make load_big_file work with read-only file #1353

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Changes from all commits
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
6 changes: 3 additions & 3 deletions flair/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
logger = logging.getLogger("flair")


def load_big_file(f):
def load_big_file(f: str) -> mmap.mmap:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And some type annotations!

"""
Workaround for loading a big pickle file. Files over 2GB cause pickle errors on certin Mac and Windows distributions.
:param f:
:return:
"""
logger.info(f"loading file {f}")
with open(f, "r+b") as f_in:
with open(f, "rb") as f_in:
# mmap seems to be much more memory efficient
bf = mmap.mmap(f_in.fileno(), 0)
bf = mmap.mmap(f_in.fileno(), 0, access=mmap.ACCESS_READ)
f_in.close()
return bf

Expand Down