Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines file#132632

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
hugovk wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromhugovk:3.14-fix-jsonlines

Conversation

hugovk
Copy link
Member

@hugovkhugovk commentedApr 17, 2025
edited by bedevere-appbot
Loading

cat input.jsonl{"ingredients":["frog", "water", "chocolate", "glucose"]}{"ingredients":["chocolate","steel bolts"]}

Before

./python.exe -m json --json-lines input.jsonlI/O operation on closed file.

After

./python.exe -m json --json-lines input.jsonl{    "ingredients": [        "frog",        "water",        "chocolate",        "glucose"    ]}{    "ingredients": [        "chocolate",        "steel bolts"    ]}

donBarbos reacted with thumbs up emoji
@hugovkhugovk added the needs backport to 3.13bugs and security fixes labelApr 17, 2025
@hugovkhugovk changed the titleFix "I/O operation on closed file" when parsing JSON Lines filegh-132631: Fix "I/O operation on closed file" when parsing JSON Lines fileApr 17, 2025
@@ -55,7 +55,7 @@ def main():
infile = open(options.infile, encoding='utf-8')
try:
if options.json_lines:
objs = (json.loads(line) for line in infile)
objs =tuple(json.loads(line) for line in infile)
Copy link
Member

Choose a reason for hiding this comment

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

This has significant memory implications for large.jsonl files. It might be better to instead move thefinally clause either to the outertry or just after thewith outfile block, but that does have implications for theinfile == outfile case.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hmm, yeah, moving it gives a blank file wheninfile == outfile...

@python-cla-bot
Copy link

python-cla-botbot commentedApr 18, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.14bugs and security fixes labelMay 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@zwarezwarezware left review comments

@brianschubertbrianschubertbrianschubert left review comments

Assignees
No one assigned
Labels
awaiting core reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixes
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@hugovk@zware@brianschubert@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp