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

  • SEARCH
  • Home
  • 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 7088809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:50:47+00:00 2026-05-28T07:50:47+00:00

I have an email account set up that triggers a python script whenever it

  • 0

I have an email account set up that triggers a python script whenever it receives an email. The script goes through several functions which can take about 30 seconds and writes an entry into a MYSQL database.

Everything runs smoothly until a second email is sent in less than 30 seconds after the first. The second email is processed correctly, but the first email creates a corrupted entry into the database.

I’m looking to hold the email data,

msg=email.message_from_file(sys.stdin)

in a queue if the script has not finished processing the prior email.

I’m using python 2.5.
Can anyone recommend a package/script that would accomplish this?

  • 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-28T07:50:48+00:00Added an answer on May 28, 2026 at 7:50 am

    I find this a simple way to avoid running a cronjob while the previous cronjob is still running.

    fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) 
    

    This will raise an IOError that I then handle by having the process kill itself.

    See http://docs.python.org/library/fcntl.html#fcntl.lockf for more info.

    Anyways you can easily use the same idea to only allow a single job to run at a time, which really isn’t the same as a queue (since any process waiting could potentially acquire the lock), but it achieves what you want.

    import fcntl
    import time
    fd = open('lock_file', 'w')
    fcntl.lockf(fd, fcntl.LOCK_EX)
    # optionally write pid to another file so you have an indicator
    # of the currently running process
    print 'Hello'
    time.sleep(1)
    

    You could also just use http://docs.python.org/dev/library/multiprocessing.html#exchanging-objects-between-processes, which does exactly what you want.

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

Sidebar

Related Questions

I have an array of input strings that contains either email addresses or account
I have an application that sends verification emails to people account email address, but
I have an application that reads emails from ONE email account (gmail application account)
I have a python application that is sending email reminders to users in different
I have multiple email addresses linked to my gmail account. I am signed up
i have an application that uses SMTP to send emails from an yahoo account.
I'm programming in PHP and would like to create web pages which have email
We have an email confirmation page for registration which can be hit with a
I have an end user that, when downloading email at home (on his laptop),
Struggling with this one. I have set up a basic email/enquiry form for a

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.