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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:54:45+00:00 2026-05-11T18:54:45+00:00

I need to pass exceptions across a thread boundary. I’m using python embedded in

  • 0

I need to pass exceptions across a thread boundary.

I’m using python embedded in a non thread safe app which has one thread safe call, post_event(callable), which calls callable from its main thread.

I am running a pygtk gui in a seperate thread, so when a button is clicked I post an event with post_event, and wait for it to finish before continuing. But I need the caller to know if the callee threw an exception, and raise it if so. I’m not too worried about the traceback, just the exception itself.

My code is roughly:

class Callback():
    def __init__(self,func,*args):
        self.func=func
        self.args=args
        self.event=threading.Event()
        self.result=None
        self.exception=None
    def __call__(self):
        gtk.gdk.threads_enter()
        try:
            self.result=self.func(*self.args)
        except:
            #what do I do here? How do I store the exception?
            pass
        finally:
            gtk.gdk.threads_leave()
            self.event.set()
    def post(self):
        post_event(self)
        gtk.gdk.threads_leave()
        self.event.wait()
        gtk.gdk.threads_enter()
        if self.exception:
            raise self.exception
        return self.result

Any help appreciated, thanks.

  • 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-11T18:54:46+00:00Added an answer on May 11, 2026 at 6:54 pm

    #what do I do here? How do I store the exception?

    Use sys.exc_info()[:2], see this wiki

    Best way to communicate among threads is Queue. Have the main thread instantiate a Queue.Queue instance and pass it to subthreads; when a subthread has something to communicate back to the master it uses .put on that queue (e.g. a tuple with thread id, exception type, exception value — or, other useful info, not necessarily exception-related, just make sure the first item of a tuple identifies the kind of info;-). The master can .get those info-units back when it wants, with various choices for synchronization and so on.

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

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What DB are you using? If it supports triggers, which… May 11, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer You have answered your own question. Static initialization order is… May 11, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer Well, in theory: yes. And practical, I think yes too.… May 11, 2026 at 8:38 pm

Related Questions

In my project I found a piece of code in which a method was
I need to add localization to the exceptions thrown by my application as a
I've got an app which is using a WCF service. Now I'd like to
I am using C# and a console app and I am using this script
I'm working on a java SE 1.5+ swing application, in conjunction with others. I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.