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