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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:51:51+00:00 2026-06-06T05:51:51+00:00

I am using the accepted answer from this question . The relevant code is

  • 0

I am using the accepted answer from this question. The relevant code is below.

import multiprocessing

def query_with_timeout(dbc, timeout, query, *a, **k):
  conn1, conn2 = multiprocessing.Pipe(False)
  subproc = multiprocessing.Process(target=do_query,
                                    args=(dbc, query, conn2)+a, 
                                    kwargs=k)
  subproc.join(timeout)
  if conn1.poll():
    return conn1.recv()
  subproc.terminate()
  raise Exception("Query %r ran for >%r" % (query, timeout))

def do_query(dbc, query, conn, *a, **k):
  cu = dbc.cursor()
  cu.execute(query, *a, **k)
  return cu.fetchall()

My call looks like this:

res = query_with_timeout(dbconn, 30, "SELECT * FROM `table`)
print res

dbconn is a connection object. It is used elsewhere in the application (outside of this timeout function) without any problem.

It appears that it joins the subprocess and waits for 30 seconds. It never enters the if conn1.poll():
return conn1.recv()
block of code though when it polls for results. Instead, I always receive the exception.

I know that the query runs (it’s a simple select), and it runs in less than a second.

Did I miss something?

  • 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-06T05:51:53+00:00Added an answer on June 6, 2026 at 5:51 am

    Well, a couple of things based on the code you’ve posted. First, you don’t ever start() the process. But perhaps that’s just a mistake you made in typing up this example?

    Second, you don’t ever send() anything via the connection.

    Here’s a simplified version of the above with expected behavior:

    import multiprocessing
    import time
    
    def simple_example(wait, timeout, query):
        conn1, conn2 = multiprocessing.Pipe(False)
        subproc = multiprocessing.Process(target=do_query, args=(wait, query, conn2))
        subproc.start()
        subproc.join(timeout)
        if conn1.poll():
            return conn1.recv()
        subproc.terminate()
        raise Exception('Query %r ran for >%r' % (query, timeout))
    
    def do_query(wait, query, conn):
        print query
        time.sleep(wait)
        conn.send(query)
    
    res = simple_example(0, 2, 'foo')
    res = simple_example(3, 2, 'foo')
    

    I fear this may simply be a problem with your example code though.

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

Sidebar

Related Questions

I'm using the accepted answer to this question to help me build an HTML
I just read this question and the accepted answer: What is JavaScript garbage collection?
I just read the accepted answer of this question , which left me with
This question has been asked before but 1) the user never accepted an answer
The accepted answer to this question , and a similar discussion at work today
This question was asked already, but the accepted answer is not helpful as the
This question has been asked here before . The accepted answer was probably obvious
This question have been answered. I recommend sumit_programmers solution below. For now, I've removed
So in this answer to the question: Hidden Features of PHP ? Talks about
I am getting this question due to another answer on here, but didn't explain

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.