【问题标题】:Error: maximum recursion depth exceeded in multipe processing错误:在多次处理中超出了最大递归深度
【发布时间】:2022-11-14 09:59:25
【问题描述】:

我尝试使用线程池运行多个处理,但出现错误maximum recursion depth exceeded

这是我的代码:

def extract_all_social_link(bio_url):
    data = extract_all_social_link(bio_url)
    return data
def run_extract_all_social_link(df, max_count, displays_steps = 1000):
    tt = time.time()
    user_data = []
    with concurrent.futures.ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
        future_to_url = dict()
        cnt = 0
        for _, row in df.iterrows():
            bio_url = row["bio_url"]
            if cnt > max_count:
                break
            if pd.isna(bio_url):
                continue
            future = executor.submit(extract_all_social_link, bio_url)
            future_to_url[future] = (bio_url)
            cnt += 1
        future_iter = concurrent.futures.as_completed(future_to_url)
        total = len(future_to_url)
        for cnt, future in tqdm(enumerate(future_iter), total=total):
            if (cnt+1) % displays_steps == 0:
                tt1 = time.time()
                print(f"{cnt+1} requests in {tt1 - tt:.3f} seconds")
                tt = tt1
            bio_url = future_to_url[future]
            try:
                data = future.result()
            except Exception as exc:
                print(f"{bio_url} generated an exception: {exc}")
        return user_data

`

这是错误:

generated an exception: maximum recursion depth exceeded

我该如何解决?

【问题讨论】:

    标签: python


    【解决方案1】:

    您可以使用https://docs.python.org/3/library/sys.html#sys.getrecursionlimit 查看和增加此限制 但一般来说这是不好的做法,因为它可以防止堆栈溢出。 通过重构代码找到一种避免如此多递归的方法。

    【讨论】:

      【解决方案2】:

      甚至不要尝试更改递归限制配置。 您必须更改 extract_all_social_link() 的代码,该代码以相同的参数 bio_url 递归调用。

      def extract_all_social_link(bio_url):
          data = extract_all_social_link(bio_url)  # infinite recursion
          return data  # never reached !!
      

      【讨论】:

        猜你喜欢
        • 2015-02-03
        • 2020-09-30
        • 2016-12-10
        • 1970-01-01
        • 2018-12-03
        • 2020-08-03
        • 2017-07-18
        • 2021-12-11
        • 1970-01-01
        相关资源
        最近更新 更多