【发布时间】:2015-02-27 01:00:49
【问题描述】:
import wx
import os
import sys
import wx.lib.plot as plot
import datetime
import urllib
import threading
pathstr = '/media/meant2b/My Passport/C Drive/Convert/GFSMaps/'
class Frame(wx.Frame):
def __init__(self, parent, id, title):
style = wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER)
wx.Frame.__init__(self, parent, id, title=title, size = (1024, 768), style=style)
self.Center()
self.panel = wx.Panel(self)
self.panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.panel.SetFocus()
self.panel.SetBackgroundColour('White')
self.bitmap = None
self.PhotoMaxSize_1 = (881)
self.CreateMenuBar()
self.model = 0
self.map = 0
self.dMinus = 0
self.Model = ['00', '06', '12', '18']
self.MDay = ['000','003','006','009','012','015','018','021','024','027','030','033','036','039','042','045','048','051','054','057','060','063','066','069','072','075','078','081','084','087','090','093','096','099','102','105','108','111','114','117','120','123','126','129','132','135','138','141','144','147','150','153','156','159','162','165','168','171','174','177','180','183','186','189','192','204','216','228','240','252','264','276','288','300','312','324','336','348','360','372','384']
self.MapType = 0
def gif1(self, event):
pathstr = '/'
for self.dMinus in range(4, -1, -1):
self.MoveCalendar() #sets date
for Counter1 in range(0, 4):
for Counter2 in range(0, 81):
if os.path.isfile(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif') == True:
continue
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.strDate + '/' + self.Model[Counter1] + '/gfs_namer_' + self.MDay[Counter2] + '_1000_500_thick.gif'
urllib.urlretrieve(url,str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
statinfo = os.stat(str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
if statinfo.st_size<21000L:
os.remove(str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
counter2 = 80
for Counter1 in range (3, -1, -1):
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.Model[Counter1] + '/gfs_namer_384_850_temp_mslp_precip.gif'
urllib.urlretrieve(url,pathstr + '850Temp384.gif')
statinfo = os.stat(pathstr + '850Temp384.gif')
if statinfo.st_size<21000:
os.remove(pathstr + '850Temp384.gif')
continue
else:
for Counter2 in range(0, 81):
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.Model[Counter1] + '/gfs_namer_' + self.MDay[Counter2] + '_850_temp_mslp_precip.gif'
urllib.urlretrieve(url,pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
statinfo = os.stat(pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
if statinfo.st_size<21000:
os.remove(pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
print('SHOW ME')
self.VGFS(event)
def gif2(self, event):
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/ao.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/AO.gif')
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/pna/nao.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/NAO.gif')
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/pna/pna.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/PNA.gif')
url = 'http://www.esrl.noaa.gov/psd/enso/mei/ts.gif'
urllib.urlretrieve(url,pathstr + '/MEI.gif')
'''
And numerous more gifs/pngs as well
'''
def All(self, event):
dl0 = threading.Thread(target = self.GFS(event))
print('MESHOW')
dl0.start()
dl1 = threading.Thread(target = self.Oscillators(event))
print('MEGO')
dl1.start()
class App(wx.App):
def OnInit(self):
self.frame = Frame(parent = None, id =-1)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__=='__main__':
app = App()
app.MainLoop()
我正在跳过大量代码。当我在 wxpython 中运行上述代码时,它运行良好,除了它按顺序运行代码,而不是同时运行所有代码。每个线程都在下载大量的 gif 和 png 文件...足够我想拆分操作以节省一些时间。它正在调用每个“线程”,但它正在等待 dl0 在运行 dl1 之前完成。我可以通过查看存储文件的目录来判断。我该如何改变它以获取它,以便它同时调用两个线程?
我将添加它,但我不知道这在 wxpython 与 tkinter 中的线程中是否会有所不同。在 tkinter 中,为了让它工作,我从来不需要添加 Thread.<strong>init</strong>(self)(由于某种原因这不会让我做 __),就像我在 wxpython 编码中看到的那样。
我现在只是想将两个单独运行的正确程序合并为一个。我也在从 tkinter 更改为 wxpython。
【问题讨论】:
-
我们必须看看 gifs1 和 gifs2 做了什么来诊断。
-
我添加了额外的代码,希望能显示问题。
标签: wxpython