| Store | Cart

urllib.urlretrieve never returns???

From: Laszlo Nagy <gand...@shopzeus.com>
Sat, 17 Mar 2012 15:13:16 +0100
See attached example code. I have a program that calls exactly the same 
code, and here is the strange thing about it:

  * Program is started as "start.py", e.g. with an open console. In this
    case, the program works!
  * Program is started as "start.pyw", e.g. with no open console under
    Windows 7 64bit - the program does not work!

In the later case, "log.txt" only contains "#1" and nothing else. If I 
look at pythonw.exe from task manager, then its shows +1 thread every 
time I click the button, and "#1" is appended to the file.

Seems like urllib.urlretrieve() does not return at all!

Using wx.PySimpleApp(redirect=True) does not help either - nothing is 
printed on the redirected console.

Unfortunately, I cannot send the whole program, because it is too big 
and also because it is confidental.

Question is: how is it possible that urllib.urlretrieve() does not 
return? It is part of a system library. What I could have possibly done 
to screw it up? And moreover, how is it possible that it does not return 
ONLY when the program is started with pythonw.exe?

Thanks,

    Laszlo


import wx
import wx.html
import urllib
import thread


class Main(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1)

        btn = wx.Button(self,-1,"Test")
        btn.Bind(wx.EVT_BUTTON,self.OnTest,btn)

        self.imgProduct = wx.html.HtmlWindow(self,-1)
        if "gtk2" in wx.PlatformInfo:
            self.imgProduct.SetStandardFonts()


        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn,0,wx.EXPAND)
        sizer.Add(self.imgProduct,1,wx.EXPAND)
        self.SetSizer(sizer)
        self.SetMinSize((800,600))
        self.SetSize((800,600))

    def OnTest(self,evt):
        imgurl = "http://www.shopzeus.hu/thumbnail.php?width=200&image=pyramid/PP0830.jpg"
        thread.start_new_thread(self.GetThumbnail,(imgurl,))

    def Log(self,msg):
        fout = open("log.txt","a")
        fout.write(repr(msg)+"\n")
        fout.close()

    def GetThumbnail(self,imgurl):
        self.Log("#1")
        try:
            fpath = urllib.urlretrieve(imgurl)[0]
        except:
            self.Log(traceback.format_exc())
            return
        self.Log("#2")
        wx.CallAfter(self.imgProduct.SetPage,"""<html><body><img src="%s"></body></html>"""%fpath)
        self.Log("#3")




app = wx.PySimpleApp(redirect=True)
frm = Main()
frm.Show()
app.MainLoop()

-- 
http://mail.python.org/mailman/listinfo/python-list

Recent Messages in this Thread
Laszlo Nagy Mar 17, 2012 02:13 pm
Chris Angelico Mar 17, 2012 04:34 pm
Laszlo Nagy Mar 17, 2012 05:31 pm
Chris Angelico Mar 17, 2012 05:53 pm
Christian Heimes Mar 17, 2012 06:18 pm
Laszlo Nagy Mar 19, 2012 07:55 am
Laszlo Nagy Mar 19, 2012 07:32 pm
Jon Clements Mar 19, 2012 11:04 pm
Steven DAprano Mar 19, 2012 11:26 pm
Laszlo Nagy Mar 20, 2012 07:08 am
Laszlo Nagy Mar 20, 2012 08:12 pm
Laszlo Nagy Mar 20, 2012 08:42 pm
Prasad, Ramit Mar 20, 2012 09:01 pm
Prasad, Ramit Mar 20, 2012 09:25 pm
Prasad, Ramit Mar 20, 2012 08:52 pm
Prasad, Ramit Mar 20, 2012 09:26 pm
Laszlo Nagy Mar 21, 2012 12:38 pm
Prasad, Ramit Mar 22, 2012 03:25 pm
John Nagle Mar 20, 2012 08:18 pm
Messages in this thread