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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:23:59+00:00 2026-06-05T17:23:59+00:00

I am writing multi-threaded python application. The main thread create a Thread pool of

  • 0

I am writing multi-threaded python application.

The main thread create a Thread pool of 5 Worker Threads.
The main thread also create a Monitor Thread.

Total: 6 threads + 1 Main Thread = 7

All Threads talk with a MySQL server (mysqldb -> libmysqlclient_r)

In my SQL wrapper i have added a Threading.Lock to the DB query function.
This Lock is a Global lock and all the Threads that query the DB, uses it.

def query(self, query):
  with lock:
   execute Query Here

Everything works well, until at some point, the main thread stuck (and so does all the threads)
I attached the GDB debugger and noticed that: (info threads)

  7 Thread 0x7f555c386700 (LWP 16077)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0
  6 Thread 0x7f555bb85700 (LWP 16078)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0
  5 Thread 0x7f555b384700 (LWP 16079)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0
  4 Thread 0x7f555ab83700 (LWP 16080)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0
  3 Thread 0x7f555a382700 (LWP 16081)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0
  2 Thread 0x7f5559b81700 (LWP 16083)  0x00007f55609141a3 in select () from /lib/libc.so.6
  1 Thread 0x7f5561e6f700 (LWP 16061)  0x00007f5561a503c0 in sem_wait () from /lib/libpthread.so.0

Th1 = Main Thread, Th2 = Monitor Thread, Th3-Th7 – Worker Threads

I noticed that All the threads beside the monitor thread are waiting on sem_wait():

(gdb) bt
#0  0x00007f5561a503c0 in **sem_wait** () from /lib/libpthread.so.0
#1  0x00000000004d44e8 in **PyThread_acquire_lock** ()
#2  0x00000000004d8982 in ?? ()
#3  0x00000000004a7ba5 in PyEval_EvalFrameEx ()

However, the monitor thread is capable of acquiring and releasing the lock (it runs every 30 sec, the select() you see is due to the sleep(30)).
I do not understand , why the rest of the threads are stuck on sem_wait(), since no one acquired the lock.

Any ideas how to solve this? how to debug this?

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-06-05T17:24:01+00:00Added an answer on June 5, 2026 at 5:24 pm

    It seems like i was using the same connection using multiple threads, which by the DOCS is not allowed.

    Tip: Make sure that each Thread has it’s own Connection object.

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

Sidebar

Related Questions

I'm writing a multi-threaded application. My worker threads get connection from an environment object
I'm writing a multi-threaded application, where there is a main thread which distributes tasks
I am writing a multi threaded application and I have concerns with 2 threads
I am writing a multi threaded application and I am also trying to work
I'am writing a multi-threaded program in C. Before creating the threads, a global python
I am writing a multi-threaded c++ application. When thread A has a very computationally
I am on MacOSX. I am writing a multi threaded program. One thread does
I'm developing a long-running multi-threaded Python application for Windows, and I want the process
I'm writing a multi-threaded server using boost::asio (for sockets), boost::thread (for threading), libconfig++ (for
I'm writing a multi-threaded server application in Java. Everything works fine , but there's

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.