diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-12-02 21:24:31 +0100 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-12-02 21:43:11 +0100 |
commit | 6b6ab3b0ea7d2c0a75222bff2d2d42712e021e23 (patch) | |
tree | 4a63ecd0f5ab355c0f72f48fd8459314b64bb77a | |
parent | 910ca89d6b75739c154edbe47ac16efb82a7285e (diff) | |
download | pidu-6b6ab3b0ea7d2c0a75222bff2d2d42712e021e23.tar.gz pidu-6b6ab3b0ea7d2c0a75222bff2d2d42712e021e23.tar.bz2 pidu-6b6ab3b0ea7d2c0a75222bff2d2d42712e021e23.zip |
Improve comments
-rwxr-xr-x | pidu | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -4,7 +4,7 @@ from multiprocessing import Process, JoinableQueue, Queue, cpu_count # Forked process main proc def proc_du(q_in,counters_count, q_out): - # count size in local process memory + # Sum up all files' 512-byte blocks allocated local_counters = [0] * counters_count # consume messages from q_in until special 'done' message while True: @@ -14,7 +14,6 @@ def proc_du(q_in,counters_count, q_out): try: for it in os.scandir(path): # Sum up file or folder physicial size (in blocks) to local_counters - # Note : this is --apparent-size mode of du, not default mode local_counters[counter_indice] += it.stat(follow_symlinks=False).st_blocks # Put more work on queue (could be taken by an other process) if it.is_dir(follow_symlinks=False): @@ -29,6 +28,12 @@ def proc_du(q_in,counters_count, q_out): # After receiving special 'done' message, put results back into q_out q_out.put(local_counters) +# Remarks on stat().st_blocks : +# - may not be available on all systems +# - are blocks of DEV_BSIZE bytes in C API +# - turns to be 512 on Linux. +# - https://docs.python.org/3/library/os.html#os.DirEntry.stat + def main(args): q_in = JoinableQueue() q_out = Queue() @@ -60,7 +65,7 @@ def main(args): except KeyboardInterrupt: pass finally: - # Forcibly kill all processes (should not be usefull in normal conditions) + # Forcibly kill all processes (should not be useful in normal conditions) list(map(lambda p: p.terminate(), process_list)) def check_positive(value): |