所以这里的这个函数就是问题所在:
def scrape(self):
url = "scrapy crawl myspider -a start_url="
if not self.onionVar.get() and not self.cnnVar.get() and not self.bbcVar.get(): #if no sites have been selected throw an error
return tkMessageBox.showerror("Error", "Err[1]: No sites selected. \n --Unable to scrape.")
if self.onionVar.get():
url = url + "http://feeds.theonion.com/theonion/daily,http://feeds.theonion.com/theonion/sports,"
if self.cnnVar.get():
url = url + "http://rss.cnn.com/rss/cnn_world.rss,http://rss.cnn.com/rss/money_latest.rss,http://rss.cnn.com/rss/cnn_allpolitics.rss," \
"http://rss.cnn.com/rss/cnn_us.rss,http://rss.cnn.com/rss/cnn_crime.rss,http://rss.cnn.com/rss/cnn_tech.rss,http://rss.cnn.com/rss/cnn_health.rss," \
"http://rss.cnn.com/rss/cnn_showbiz.rss,http://rss.cnn.com/rss/cnn_travel.rss,http://rss.cnn.com/rss/cnn_living.rss,"
if self.bbcVar.get():
url = url + "http://feeds.bbci.co.uk/news/rss.xml#,"
cmdline.execute(url.split())
我正在使用 Tkinter 制作我的第一个 GUI 程序,当我调用此函数时,最后一行 cmdline.execute(url.split()) 将运行,然后在完成后关闭程序。我认为我需要做的是创建一个新线程并在其中运行函数。这是我尝试做的:self.b = Button(master, text="Scrape", command=thread.start_new_thread(self.scrape, ())),但问题是 Tkinter将所有返回值绑定(bind)到命令参数,以便它在启动时自动运行抓取功能。如果有人有任何想法,我们将不胜感激。
抱歉,如果这没有意义,我不擅长解释事情。谢谢你的时间 - 山姆
请您参考如下方法:
走向分布式
在迫切需要分布式处理时,设置进程到进程的消息传递,最好使用一些智能的、高级的、无代理的消息传递框架,并享受分布式事件处理的全部功能。
Tkinter 将允许您的代码使用相同的 Tk() 处理本地上下文处理(自己的 UI 事件)以及远程事件。 mainloop() 控制循环调度程序。
尝试的工具
可能会考虑测试 ZeroMQ 或 nanomsg(而不是尝试重新发明低级 I/O 和线程间信号),因为它们具有出色的服务、出色的性能和智能的现成原语(原型(prototype)) ) 用于更复杂、高度可扩展、容错、负载平衡和其他设计的更多乐高式组件。
多线程多主机分布式用户界面示例
Tkinter驱动 python GUI 交互(参数化 + 实时 matplotlib 图)远程主机进程,ZeroMQ 连接,根据
python请求提供静态市场数据分布式远程进程池、ZeroMQ 互连、针对服务器端专有交易执行接口(interface)编排负载均衡的交易执行服务
远程 C/MQL4、多线程进程、ZeroMQ 互连、从 python 计算密集型支持接收并将部分输入可视化为专有交易终端 UI 上的实时预测图形
项目已实现多主机/多头实时 GUI 并将阻塞事件重新分配到负载平衡/公平队列池-of-remote-process-es 以削减毫秒和微秒不需要花费和浪费在主集群上的非核心工作上。
