Python多线程不会提高速度


VIP
2025-02-23 02:21:52 (16天前)
  1. 我有2个单独的文件,包含一个地方的坐标,另一个包含街道和邮政编码。

通过使用pandas我想创建一个包含所有三个的新Dataframe …

2 条回复
  1. 0# 12345 | 2019-08-31 10-32



    Python使用GIL(

    全球翻译锁

    ),它可以防止多个线程一次执行Python字节码。换句话说,一次只执行一个线程,因此在您的情况下几乎不可能实现任何显着的性能提升。



    你应该尝试使用Python

    多处理池

    相反,它不受GIL的限制:




    1. from multiprocessing import Pool


    2. pool = Pool(5)
      company_items = pool.map(group_comp_with_coord, test.iterrows())

    3. </code>

登录 后才能参与评论