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 8753329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:24:15+00:00 2026-06-13T13:24:15+00:00

I made a loop in Python that calls itself to repeatedly check for new

  • 0

I made a loop in Python that calls itself to repeatedly check for new entries in a database. On first execution, all affected rows are shown fine. Meanwhile, I add more rows into the database. On the next query in my loop, the new rows are not shown.

This is my query-loop:

def loop():
    global mysqlconfig # username, passwd...
    tbd=[] # this is where I save the result
    conn = MySQLdb.connect(**mysqlconfig)
    conn.autocommit(True)
    c = conn.cursor()
    c.execute("SELECT id, message FROM tasks WHERE date <= '%s' AND done = 0;" % now.isoformat(' '))
    conn.commit()
    tbd = c.fetchall()      
    print tbd
    c.close()
    conn.close()

    time.sleep(5)
    loop()
loop()

This is the SQL part of my Python insertion-script:

conn = MySQLdb.connect(**mysqlconfig)
conn.autocommit(1)
c = conn.cursor()
c.execute("INSERT INTO tasks (date, message) VALUES ('{0}', '{1}');".format("2012-10-28 23:50", "test")) 
conn.commit()
id = c.lastrowid
c.close()
conn.close()

I tried SQLite, I tried Oracle MySQL’s connector, I tried MySQLdb on a Windows and Linux system and all had the same problem. I looked through many, many threads on Stackoverflow that recommended to turn on autocommit or use commit() after an SQL statement (ex. one, two, three), which I tried and failed.

When I added data with HeidiSQL to my database it showed up in the loop query, but I don’t really know why this is. Rows inserted with mysql-client on Linux and my Python insertion script never show up until I restart my loop script.

I don’t know if it’s the fact that I open 2 connections, each in their own script, but I close every connection and every cursor when I’m done with them.

  • 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-06-13T13:24:16+00:00Added an answer on June 13, 2026 at 1:24 pm

    The problem could be with your variable now. I don’t see anywhere in the loop that it is being reset.

    I’d probably use the mysql NOW() function:

    c.execute("SELECT id, message FROM tasks WHERE date <= NOW() AND done = 0;")
    

    It looks like the time you are inserting into the database is a time in the future. I don’t think your issue is with your database connection, I think it’s something to do with the queries you are doing.

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

Sidebar

Related Questions

I made an application that passes trough an XML file and extracts the entries
I have a simple SWF video loop I made a couple years ago that
So here's what I see this code doing: An array is made A loop
I made a while loop inside a program and the program reaches the while
Made this nice little loop for hiding and showing div's, works as a charm
I made an IRC bot which uses a while true loop to receive whatever
I made an iphone app to capture image from camera and to set that
I have two algorithms of finding primes, in Python. The inner loop of each
I currently have a game loop that fires off about 20 times per second
I made a while loop in php: <?php include_once(connect.php); $search=mysql_query(SELECT * from chat ORDER

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.