Python 2.7 Python/Scrapy等待完成

Python 2.7 Python/Scrapy等待完成,python-2.7,scrapy,wait,Python 2.7,Scrapy,Wait,试着找一个我正在做的项目来等待抓取的结果。对Python来说非常陌生,但我学习得很快,到目前为止我一直很喜欢它。这里是我的补救功能,刷新我的爬行 def refreshCrawls(): os.system('rm JSON/*.json) os.system('scrapy crawl TeamGameResults -o JSON/TeamGameResults.json --nolog') #I do this same call for 4 other c

试着找一个我正在做的项目来等待抓取的结果。对Python来说非常陌生,但我学习得很快,到目前为止我一直很喜欢它。这里是我的补救功能,刷新我的爬行

def refreshCrawls():
     os.system('rm JSON/*.json)

     os.system('scrapy crawl TeamGameResults -o JSON/TeamGameResults.json --nolog')
     #I do this same call for 4 other crawls also
在分析参数时,在“main function”中的for循环中调用此函数:

for i in xrange(1,len(sys.argv)):
     arg = sys.argv[i]
     if arg == '-r':
          pprint('Refreshing Data...')
          refreshCrawls()
这一切都可以正常工作并更新JSON文件,但是我的应用程序的其余部分并没有像我愚蠢地期望的那样等待它。直到我将应用程序移到Pi,这个可怜的小家伙不能很快刷新,我才发现这个问题,有什么建议可以解决吗


我的快速肮脏的回答是,将它拆分成不同的自动脚本,在我运行自动“主功能”之前运行一个小时左右,或者使用睡眠计时器,但如果有一些低挂果实可以解决这一问题,我宁愿正确地做这件事。我确实喜欢能够在命令行中输入refresh参数

不要使用
os
而使用
子流程

from subprocess import Popen
import shlex

def refreshCrawls():
     os.system('rm JSON/*.json')
     cmd = shlex.split('scrapy crawl TeamGameResults -o JSON/TeamGameResults.json --nolog')
     p = Popen(cmd)
     #I do this same call for 4 other crawls also
     p.wait()

for i in xrange(1,len(sys.argv)):
     arg = sys.argv[i]
     if arg == '-r':
          pprint('Refreshing Data...')
          refreshCrawls()

谢谢,这样更好。我必须把我的论点作为一个清单来发表,以供参考。[刮胡子','爬行','TeaPosith.@ JordanWayneCrabb更新了我的脚本,这样你就不用手动创建列表了。如果这个答案解决了这个问题,请考虑接受它。