什么是Python的“內置方法獲取”?我怎樣才能加快速度? - What is Python's “built-in method acquire”? How can I speed it up? -开发者知识库

什么是Python的“內置方法獲取”?我怎樣才能加快速度? - What is Python's “built-in method acquire”? How can I speed it up? -开发者知识库,第1张

I'm writing a Python program with a lot of file access. It's running surprisingly slowly, so I used cProfile to find out what was taking the time.

我正在編寫一個包含大量文件訪問權限的Python程序。它運行得非常慢,所以我使用cProfile來找出花費時間的東西。

It seems there's a lot of time spent in what Python is reporting as "{built-in method acquire}". I have no idea what this method is. What is it, and how can I speed up my program?

似乎有很多時間花在Python報告的“{內置方法獲取}”上。我不知道這個方法是什么。它是什么,我怎樣才能加快我的計划?

3 个解决方案

#1


Without seeing your code, it is hard to guess. But to guess I would say that it is the threading.Lock.acquire method. Part of your code is trying to get a threading lock, and it is waiting until it has got it.

沒有看到你的代碼,很難猜到。但是猜測我會說它是threading.Lock.acquire方法。你的部分代碼試圖獲得一個線程鎖,它一直等到它獲得它。

There may be simple ways of fixing it by

可能有簡單的方法來解決它

  • restructuring your file access,
  • 重建文件訪問權限,

  • not locking,
  • using blocking=False,
  • or even not using threads at all.
  • 甚至根本不使用線程。

But again, without seeing your code, it is hard to guess.

但同樣,在沒有看到你的代碼的情況下,很難猜到。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复