Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:42:59+00:00 2026-05-25T20:42:59+00:00

I have a Python script that checks on a pickup directory and processes any

  • 0

I have a Python script that checks on a pickup directory and processes any files that it finds, and then deletes them.

How can I make sure not to pickup a file that is still being written by the process that drops files in that directory?

My test case is pretty simple. I copy-paste 300MB of files into the pickup directory, and frequently the script will grab a file that’s still being written. It operates on only the partial file, then delete it. This fires off a file operation error in the OS as the file it was writing to disappeared.

  • I’ve tried acquiring a lock on the file (using the FileLock module) before I open/process/delete it. But that hasn’t helped.

  • I’ve considered checking the modification time on the file to avoid anything within X seconds of now. But that seems clunky.

My test is on OSX, but I’m trying to find a solution that will work across the major platforms.

I see a similar question here (How to check if a file is still being written?), but there was no clear solution.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:43:00+00:00Added an answer on May 25, 2026 at 8:43 pm

    As a workaround, you could listen to file modified events (watchdog is cross-platform). The modified event (on OS X at least) isn’t fired for each write, it’s only fired on close. So when you detect a modified event you can assume all writes are complete.

    Of course, if the file is being written in chunks, and being saved after each chunk this won’t work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that checks a certain folder for new files and
I have a python script that analyzes a set of error messages and checks
The scenario: We have a python script that checks thousands of proxys simultaneously. The
I have written a Python script that checks a certain e-mail address and passes
I have a python script that checks code for coding convention errors. It does
I have a Python command line script that connects to a database, generates files
I have python script that uses pysvn and checks out or updates a local
I have a Python script that needs to execute an external program, but for
I have a python script that is a http-server: http://paste2.org/p/89701 , when benchmarking it
I have a python script that I would like to add a Shutdown when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.