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

Subject: Issue with Deleting Temporary Files After Processing PDF #432

Open
Popachka opened this issue Dec 19, 2024 · 0 comments
Open

Subject: Issue with Deleting Temporary Files After Processing PDF #432

Popachka opened this issue Dec 19, 2024 · 0 comments

Comments

@Popachka
Copy link

Popachka commented Dec 19, 2024

Hello, community!

I am facing an issue with handling and deleting temporary files when working with asynchronous code in Python. In the process of downloading a file and writing it to a temporary file, I am using the aiofiles library for asynchronous file writing. However, after processing and performing further actions, the file is not deleted automatically.

Here’s my code for downloading the file and writing it to a temporary file:

async with aiohttp.ClientSession() as session:
    async with session.get(url) as response:
        if response.status != 200:
            raise Exception(f"Failed to download file: {response.status}")
        file_data = await response.read()

# Creating a temporary file
tmp_file_path = Path(tempfile.mktemp(suffix=".pdf"))

# Writing data to the temporary file asynchronously using aiofiles
async with aiofiles.open(tmp_file_path, "wb") as tmp_file:
    await tmp_file.write(file_data)

# Returning the file path
return tmp_file_path

`
fter calling self._pdf_marker_parser.load_data(file_path), the temporary file is not automatically closed or deleted, which leads to resource leakage.

Is there a better way to ensure that the temporary file is properly deleted after it's no longer needed, considering I’m using asynchronous operations?

Looking forward to your suggestions and solutions!


This version is clearer and more focused on the issue you're facing. Let me know if you'd like any further modifications!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant