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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:24:35+00:00 2026-05-23T02:24:35+00:00

I have a chunk of code like this def f(x): try: g(x) except Exception,

  • 0

I have a chunk of code like this

def f(x):
    try:
       g(x)
    except Exception, e:
       print "Exception %s: %d" % (x, e)

def h(x):
    thread.start_new_thread(f, (x,))

Once in a while, I get this:

Unhandled exception in thread started by 
Error in sys.excepthook:

Original exception was:

Unlike the code sample, that’s the complete text. I assume after the “by” there’s supposed to be a thread ID and after the colon there are supposed to be stack traces, but nope, nothing. I don’t know how to even start to debug 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-23T02:24:36+00:00Added an answer on May 23, 2026 at 2:24 am

    The error you’re seeing means the interpreter was exiting (because the main thread exited) while another thread was still executing Python code. Python will clean up its environment, cleaning out and throwing away all of the loaded modules (to make sure as many finalizers as possible execute) but unfortunately that means the still-running thread will start raising exceptions when it tries to use something that was already destroyed. And then that exception propagates up to the start_new_thread function that started the thread, and it will try to report the exception — only to find that what it tries to use to report the exception is also gone, which causes the confusing empty error messages.

    In your specific example, this is all caused by your thread being started and your main thread exiting right away. Whether the newly started thread gets a chance to run before, during or after the interpreter exits (and thus whether you see it run as normal, run partially and report an error or never see it run) is entirely up to the OS thread scheduler.

    If you’re using threads (which is not a bad thing to avoid) you probably want to not have threads running while you’re exiting the interpreter. The threading.Thread class is a better interface for starting new threads, and it will make the interpreter wait for all threads by default, on exit. If you really don’t want to wait for a thread to end, you can set its ‘daemonic’ flag in the Thread object to get the old behaviour — including the problem you see here.

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

Sidebar

Related Questions

We have a chunk of code something like this // semi-pseudo code def result
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I have this simple code that needs to get a chunk of a large
Let's say you have the following chunk of code: <div id=container> <someelement>This is any
I currently have this chunk of model code: class Book(models.Model): title = models.CharField(max_length=100) num_pages
I'm looking for a better way to this. I have a chunk of code
I have this chunk of code which is placed in accelerometer: didAccelerate which changes
I have this chunk of code which adds up all the players hurt on
In my project I have two chunk of code which I would like to
I have a chunk of code where it appears that a variable is changing

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.