From <https://www.infoworld.com/article/4018856/4-tips-for-getting-started-with-free-threaded-python.html>:
As an example, if you have a job that writes a lot of files,
having each job in its own thread is less effective if each job
also writes the file. This is because writing files is an
inherently serial operation. A better approach would be to divide
jobs across threads and use one thread for writing to disk. As
each job finishes, it sends work to the disk-writing job. This
way, jobs don’t block each other and aren’t themselves blocked by
file writing.
Actually, blocking system calls (whether for I/O or something else)
only block the current thread. So having each thread do its own I/O
should be faster than funnelling it all through one bottleneck thread.
If you don’t want your worker threads blocked waiting for I/O to
complete, then each worker context can be a pair of threads: one does
the CPU-intensive stuff, while the other handles the blocking I/O.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 148:01:37 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
33 files (6,120K bytes) |
Messages: | 2,410,931 |