Skip to content

ValueError: I/O operation on closed file when parsing feeds with leading newline in multiprocessing #511

Description

@Alvaro-Kothe

When parsing an RSS feed string that starts with a newline before the XML declaration inside a ProcessPoolExecutor, feedparser.parse returns a FeedParserDict object that cannot be pickled without raising:

ValueError: I/O operation on closed file

This error happens during the result pickling step after the worker finishes, not directly inside feedparser.parse.

Minimal Reproducible Example

import feedparser
from concurrent.futures import ProcessPoolExecutor

FEED_STR = """
<?xml version='1.0' encoding='UTF-8'?>
<rss version="2.0">
<channel>
<title>Foo</title>
<link>https://foo.com/</link>
<item><title>Title 1</title><link>https://foo.com/1</link><pubDate>Thu, 05 Jun 2025 18:27:58 -0000</pubDate></item>
</channel>
</rss>
"""

def parse_and_return_full(raw_feed: str):
    return feedparser.parse(raw_feed)

if __name__ == "__main__":
    with ProcessPoolExecutor() as pool:
        future = pool.submit(parse_and_return_full, FEED_STR)
        result = future.result()

Removing the initial newline from FEED_STR prevents the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions