Hello L.,
Wednesday, January 11, 2006, 7:15:48 PM, you wrote:
Hi!
Yes, I'm using httplib. I'll post a bit of my code:
def OnClick(self, event):
......
##Part for retrieving the image URL
h=httplib.HTTP("phobos.apple.com")
searchString="/WebObjects/MZSearch.woa/wa/advancedSearchResults?artistTerm='"+
artistName + "' songTerm='' albumTerm='" + albumName + "'"
h.putrequest("GET", searchString)h.putheader("Referrer","http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZSearch.woa/wa/advancedSearch?origin=xml"\)
h.putheader("Host",
"ax.phobos.apple.com.edgesuite.net")
h.putheader("User-Agent", "iTunes/6.0.2
(Windows; U;Microsoft Windows XP Professional Service Pack 2
(Build 2600)) DPI/96")
h.putheader("Accept-Language", "en-us, en;q=0.50")
h.putheader("Cookie", "countryVerified=1")
h.putheader("Accept-Encoding", "gzip, x-aes-cbc")
h.putheader("Connection", "close")
h.endheaders()
errcode, errmsg, headers = h.getreply()
f=h.getfile()
data=f.read()
f.close()
The OnClick event is triggered by pressing a button in
myMainFrame. What do you mean by this:
"I suggest you start the downloading as a non-blockingevent"?
Is that a specual type of event?
the_shelter wrote: Hello L.,
Wednesday, January 11, 2006, 6:52:25 PM, you wrote:
Hi!
I'm having a problem with a program I wrote.. (or I wouldn't be here, I
guess ;))
The program fetches artwork (album covers) from the internet, but when
the files are big the program becomes unresponsive.
Windows thinks the program has frozen (I think) and marks it at "Not
Responding" in the Task Manager..
Is there a way to prevent this from happening?
Thanks in advance!
---------------------------------------------------------------------
To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.orgLF> For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.orghow do you fetch these pics?Do you start a threat, so your main app is not blocked?
I don't think that windows deliberately marks your app 'not
responding'.
I suggest you start the downloading as a non-blocking event. This way
you have still controll over the child process and still be able to
work ww/ your main app.
Let me know if you need further assistance.
BTW, what do you use for downloading? httplib?
O.K.
from what I see you read the whole file in in one big chunk at the end
of the download. You should be better off
reading the http stream directly into the file instead of waiting for the whole
transfer to be completed and then write it to file (i.e. you write
chunk by chunk- this way you can also resume a download from most http
servers when a connection is lost- this is done via the 'Range' header
statement - see the rfc http specs for further details).
Second I suggest you start using a thread.
If you are not familiar w/ threads yet, start getting into the
subject- it will pay off. A simple thread app looks like this:
import thread
import time
def WhataThread(tid):
f=open("file.txt", 'w')
f.write("What a thread ;-)")
print "Closing file after successful write job."
f.close()
thread.start_new(WhataThread, (1, )) # start as a thread so it runs independently
print thread.get_ident() # print the thread's id
print "If the program's main loop, the parent, ends here, the child, our thread will be killed."
print "We give the thread 10 seconds to do it's job."
time.sleep(10)
print "Ending main loop and thus killing all child processes."
It's a rather dull example (could not come up w/ something smarter on
the spot), I know. but essentially there is all you
have to know to start threading
define a new function that starts a thread and returns the thread's
id. Then trigger it from your OnClick().
Your main app will be still responding to user interaction, the
download starts 'in the background'. It could send info of what it+#s
doing to your main window, a progress bar, or whatever(also trigger
something in case the download is incomplete or lost ...).
Hope that helps a little
ยทยทยท
--
Best regards,
the_shelter mailto:pdftex@the-shelter.de