Can you please tell me what methods in Python can be used to limit the disk read speed for a particular process? I'm interested in setting a limit on read only operations, with no limit on writes for a particular process on a windows system. Can this be implemented through standard libraries or third party tools? Let's take CrystalDiskMark as an example.
The effect should be as follows:
#🔒 Python slows down the process?
9 messages · Page 1 of 1 (latest)
@chrome night
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
is the process you're trying to limit a python process, e.g. some code that uses with open.. to read from disk?
if so you could create a function that reads in chunks, with a delay after each read based on the time of the previous read
No, it has to be any randomly selected program.
Yes, you can limit the disk reading speed in Python by controlling the rate at which data is read from the disk. Python itself doesn’t provide a direct API to throttle disk I/O speed, but you can implement a custom method to do this by reading data in small chunks and introducing delays between each read operation. This allows you to limit the rate at which data is being processed from the disk.
You can use Python’s time.sleep() function to introduce a delay between reading chunks of data, effectively limiting the reading speed.
with open(file_path, 'rb') as file:
while True:
chunk = file.read(chunk_size)
if not chunk:
break
# Process the chunk (or just print it in this case)
print(chunk) # or process the chunk
time.sleep(delay_per_chunk) # Sleep to limit the reading speed
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.