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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:03:39+00:00 2026-06-10T01:03:39+00:00

I am using python with gtk. I want to download a file, and while

  • 0

I am using python with gtk.
I want to download a file, and while this is happening i draw an animated gif on the window.
But everytime the download starts, the gif is freezing. I thought the gobject call should fix this, but seems not like.

The call is:

in the gui class

  ...
  gobject.timeout_add(3000, self.load)
  gtk.main()

and the load function:

 def load(self):
     ul = urllib2.open('http://xxxx/')
     data = ul.read()
     while gtk.events_pending():
          gtk.main_iteration()
     return True

with every call of load the gui stacks. Any way to do that better?

original code:

self.opener = urllib2.build_opener() 
self.opener.addheaders.append(('Cookie', self.cookie)) 
self.state = self.opener.open('http://'+gd_adress+'/state.cst?Lang=en')
self.state_data = self.state.read()
  • 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-10T01:03:41+00:00Added an answer on June 10, 2026 at 1:03 am

    You need to use an asynchronous call that integrates with the GObject main loop.

    Probably the easiest is to use GIO:

    import gio
    
    f = gio.File(uri='http://xxxx/')
    def on_ready(gdaemonfile, result):
        data, length, tag = f.load_contents_finish(result)
    f.load_contents_async(on_ready)
    

    Jono Bacon has a great writeup: http://www.jonobacon.org/2010/03/15/download-files-async-with-gio-and-python/

    Unfortunately GIO doesn’t support setting HTTP cookies as far as I can tell. In that case the best option is probably to use threads and use GLib.idle_add to return data to the main loop, as in Webkit threads with PyGObject on Gtk3:

    import threading
    import glib
    glib.threads_init()
    
    def load_data():
        opener = urllib2.build_opener() 
        opener.addheaders.append(('Cookie', cookie)) 
        state = opener.open('http://'+gd_adress+'/state.cst?Lang=en')
        state_data = state.read()
        glib.idle_add(on_read_data, state_data)
    thread = threading.Thread(target=load_data)
    thread.start()
    

    The idea is that this encapsulates the blocking call in a thread that returns data to the main thread when it is ready, so the rest of your code can ignore the fact that threads are being used.

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

Sidebar

Related Questions

Using Python 2.5 and httplib...... I am admittedly a python novice.....but this seems straight
I'm developing an application using python gtk+ and glade. My glade file format is
Using Python's csv module, is it possible to read an entire, large, csv file
Using Python, I want to know whether Java is installed.
Using Python I want to randomly rearrange sections of a string based on a
I want to view a pdf document by embedding it in Python using the
I'm using python and want to embed gtk3 widgets in clutter stage. However, it
i am writing a text editor in gtk 3 using python. in gtk 2
I'm working on a project using Python and pyGTK. I have a window whose
Using Python 2.6, Twisted 10.1, and GTK+ 2.22, with latest pygtk installed, I'm having

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.