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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:24:21+00:00 2026-06-14T08:24:21+00:00

I would like to transfer data to threading class, but I can’t get what

  • 0

I would like to transfer data to threading class, but I can’t get what is wrong. The code below is from this question and I changed it a little.

This is a code:

import gtk, gobject, threading, time

gobject.threads_init()

class T(threading.Thread):
    pause = threading.Event()
    stop = False

    def start(self, data, *args):
        super(T, self).start()

    def run(self, data):
        while not self.stop:
            self.pause.wait()
            gobject.idle_add(lambda *a : self.rungui(data))
            time.sleep(0.1)

    def rungui(self, data):
        print "printed"
        print data

thread = T()

class Start:

        def toggle_thread(self, data=None, *args):
                if not thread.is_alive():
                    thread.start(data)
                    thread.pause.set()
                    self.button.set_label('Pause Thread')
                    return

                if thread.pause.is_set():
                    thread.pause.clear()
                    self.button.set_label('Resume Thread')
                else:
                    thread.pause.set()
                    self.button.set_label('Pause Thread')

        def __init__(self):
                thread = T()
                window = gtk.Window()
                self.button = gtk.ToggleButton('Start Thread')
                data = 3
                self.button.connect('toggled', lambda *a : self.start(data), None)
                window.add(self.button)
                self.button.show()
                window.show()

        def start(self, data=None):
                self.toggle_thread(data)

        def main(self):
                gtk.main()

if __name__ == "__main__":
        start = Start()
        start.main()

What do I have to correct to get threading fully working?

  • 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-14T08:24:22+00:00Added an answer on June 14, 2026 at 8:24 am

    Don`t work with gtk out of gui thread. That about:

    gobject.idle_add(self.rungui)
    

    Example at your link work fine, but need system kill command for termination.
    And super() can`t bring arguments to run() function.

    My threads initialization looks like this:

    class VirtService(threading.Thread):
            def __init__(self, queue):
                    threading.Thread.__init__(self)
                    self.queue = queue
    
            def thread_loop(self):
                    while self.queue.qsize():
                            data_command = self.queue_get()
    
    ...
    
    queue = Queue()
    
    if __name__ == '__main__':
            gobject.threads_init()
            vs = VirtService(queue)
    

    And you may use Queue for data translation to both directions. You may use also queue for command. In non-graphical thread create c++ poll() analog through Queue.qet(), and in gui thread queue.put()

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

Sidebar

Related Questions

I would like to be able to transfer data from one activity to another
How can i transfer data between two device? I would like to transfer data
I would like to know the best way to transfer data from a web
We would like to know the source code for transfer the session data to
I want to get to know how I can transfer data easily between 2
I would like to transfer my existing SQL Azure location to other one, but
I want to upload data from Google Cloud Storage to BigQuery, but I can't
I have an app with Core Data and I would like to transfer its
I am writing a data transfer application using a servlet and would like to
I am trying to make a poker game and would like to transfer data

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.