简体   繁体   中英

What is Python's “built-in method acquire”? How can I speed it up?

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.

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?

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.

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.

you want to look for cpu used, not for "total time used" from within that method--that might help. Sorry I don't use python but that's how it is for me in ruby :) -r

Using threads for IO is a bad idea. Threading won't make your program wait faster. You can achieve better results by using asynchronous I/O and an event loop; Post more information about your program, and why you are using threads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM