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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:26+00:00 2026-05-22T17:23:26+00:00

I want to play with the thread-bugs with PyGTK. I have this code so

  • 0

I want to play with the thread-bugs with PyGTK. I have this code so far:

#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import gtk
import threading
from time import sleep

class SomeNonGUIThread(threading.Thread):
    def __init__(self, tid):
        super(SomeNonGUIThread, self).__init__()
        self.tid = tid

    def run(self):
        while True:
            print "Client #%d" % self.tid
            sleep(0.5)

class App(threading.Thread):
    def __init__(self):
        super(App, self).__init__()

        self.window = gtk.Window()
        self.window.set_size_request(300, 300)
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.connect('destroy', gtk.main_quit)

        self.window.show_all()

    def run(self):
        print "Main start"
        gtk.main()
        print "Main end"


if __name__ == "__main__":
    app = App()

    threads = []
    for i in range(5):
        t = SomeNonGUIThread(i)
        threads.append(t)

    # Ready, set, go!
    for t in threads:
        t.start()

    # Threads work so well so far
    sleep(3)

    # And now, they freeze :-(
    app.start()

It does that NonGUIThreads are running for 3 seconds concurently. Afterwards, the window is shown and other threads are stoped! After closing the window, threads are running again.

How it is possible, that gtk.main() is able to block other threads? The threads do not depend on any lock, so they should work during the window is shown.

  • 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-22T17:23:26+00:00Added an answer on May 22, 2026 at 5:23 pm

    You have to call gobject.threads_init() before you do anything Gtk related.

    More info in PyGtk’s FAQ

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

Sidebar

Related Questions

I have Url like http://www.logisticinfotech.com/client/Malasiya%20Cup/movie.mp4 i want play this video in my video player
I saw this script in another thread on stack overflow and tried to play
I have been trying to play around with this for a long time and
I have list of video files in datagridview object, and I want to play
For the computer game I'm making, I obviously want to play sound. So far,
In my main activity I have a button with the text Play. I want
I want to play around with silverlight without having to buy a Visual Studio
I want to play around a bit with FLASH for app development. I'm looking
I want to play a movie file or any animation file till the time
I want to play a sound while my splash screen gets data from the

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.