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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:24:21+00:00 2026-05-16T08:24:21+00:00

From what I understand about twisted, nothing running in the reactor thread should block.

  • 0

From what I understand about twisted, nothing running in the reactor thread should block. All blocking activities should be delegated to other threads, to fire callbacks back into the reactor thread when they’re done.

So does this apply to gtk things as well? For example, I want to display a “connection failed” message if the connection… failed. Do I do:

def connectionFailed(self, reason):
    dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                      buttons=gtk.BUTTONS_CLOSE,
                      message_format="Could not connect to server:\n%s" % (
                          reason.getErrorMessage()))
    dlg.run()

or:

def connectionFailed(self, reason):
    dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                      buttons=gtk.BUTTONS_CLOSE,
                      message_format="Could not connect to server:\n%s" % (
                          reason.getErrorMessage()))
    reactor.callInThread(dlg.run)

or:

def connectionFailed(self, reason):
    def bloogedy():
        dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                          buttons=gtk.BUTTONS_CLOSE,
                          message_format="Could not connect to server:\n%s" % (
                              reason.getErrorMessage()))
        dlg.run()
    reactor.callInThread(bloogedy)

?

EDIT: Ooh ok, the latter two really messed up. so I guess the answer is the first. Then my question is: why? It seems like this would block the reactor thread.

  • 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-16T08:24:21+00:00Added an answer on May 16, 2026 at 8:24 am

    Your problem doesn’t actually have anything to do with threads and GUIs. You should always use Twisted and GTK from the same thread: there’s no need to do otherwise.

    Your problem is that you are using gtk.Dialog.run(). This is an API that you should never use, Twisted or not. It runs a re-entrant main loop, which causes your current event handler to block, but allowing other event handlers to execute one layer down the stack. GTK has excellent support for re-entrant main loops, but Twisted doesn’t (and that’s okay because like I said, you shouldn’t use them).

    MessageDialog.run won’t work in a thread, anyway, so you don’t actually have that option. It will cause unpredictable behavior which can cause your application to behave weirdly or crash. GTK has fine support for threads, but there are things that you are just never supposed to do with a thread because it doesn’t make any sense, and this is one of them.

    If you’re dealing with code that isn’t doing any processing, but just wants to wait for something to happen (like waiting for a user to press a button on a dialog) you should use functions which return Deferreds, not threads. As it so happens, gtk.Dialogs will emit a signal at the point where they are responded to: “response“. You can use this to wire up a very simple function that displays your message with a dialog and returns a Deferred when it’s complete. Here’s an example:

    def showMessage(text):
        mdlg = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
                                 buttons=gtk.BUTTONS_CLOSE,
                                 message_format=text)
        result = Deferred()
        def response(dialog, response_id):
            mdlg.destroy()
            result.callback(response_id)
            return False
        mdlg.connect("response", response)
        mdlg.show_all()
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.