程序类被卡住/空闲,并且在Anaconda /命令行提示符中进行第一次调用后不执行其余调用,但在Spyder中有效

时间:2019-03-16 19:59:29

标签: python python-3.x command-line anaconda spyder

我正在尝试使用anaconda提示符运行我的python脚本。它在第一次通话时运行平稳,但在此停止。我在Spyder上尝试过,它可以工作,但我希望它在anaconda提示符或命令行下工作。有什么原因吗?

from decompress import decompress
from reddit import reddit
from clean import clean
from wikipedia import wikipedia

def main():
    dir_of_file = r"D:\Users\Jonathan\Desktop\Reddit Data\Demo\\"
    print('0. Path: ' + dir_of_file)
    reddit_repo = reddit()
    wikipedia_repo = wikipedia()
    pattern_filter = "*2007*&*2008*"
    print('1. Creating data lake')
    reddit_repo.download_files(pattern_filter,"https://files.pushshift.io/reddit/submissions/",dir_of_file,'s') 
    reddit_repo.download_files(pattern_filter,"https://files.pushshift.io/reddit/comments/",dir_of_file,'c')         

if __name__ == "__main__":
    main()

已下载的RS是正在运行的以下代码行:

reddit_repo.download_files(pattern_filter,"https://files.pushshift.io/reddit/submissions/",dir_of_file,'s') 

enter image description here 更新

添加了类/功能

class reddit:

    def multithread_download_files_func(self,list_of_file):
        filename = list_of_file[list_of_file.rfind("/")+1:]
        path_to_save_filename = self.ptsf_download_files + filename
        if not os.path.exists(path_to_save_filename): 
            data_content = None
            try:
                request = urllib.request.Request(list_of_file)
                response = urllib.request.urlopen(request)
                data_content = response.read()
            except urllib.error.HTTPError:
                print('HTTP Error')
            except Exception as e:
                print(e)
            if data_content:
                with open(path_to_save_filename, 'wb') as wf:    
                    wf.write(data_content)                 
                    print(self.present_download_files + filename)                        

    def download_files(self,filter_files_df,url_to_download_df,path_to_save_file_df,prefix):
        #do some processing
        matching_fnmatch_list.sort()

        p = ThreadPool(200)
        p.map(self.multithread_download_files_func, matching_fnmatch_list)

1 个答案:

答案 0 :(得分:0)

这是下载过程,需要花费大量时间。我更改了网络,它按预期工作。因此,cmd或anaconda提示符没有问题