-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageGrab gives OSError randomly #7133
Comments
Could you estimate how often the error occurs? 1 out of every 10 attempts? 1 out of every 100? Does the error happen without FastAPI? In other words, if you just run |
The error is occurring at Lines 439 to 440 in 2467db4
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard states
You're sure there's no pattern you can discern to the error? No clipboard operations you're running sometimes and not others? If you copy something, and then try grabbing the clipboard repeatedly afterwards, does it pass every time? In other words, once there is a failure, does |
There is no clear frequency of occurrence, sometimes it occurs twice in a row while other times it could run perfectly for many attempts. I have yet to find any pattern, it fails sometimes when I am not doing anything else on the laptop at all except for the program. I have tried making multiple requests quickly, repeatedly grabbing the clipboard, copying something else into the clipboard beforehand etc. It does seem to have a higher rate of occurrence when I make multiple requests very quickly, but not any pattern I can find. Also when it fails, I usually just need to retry and it will work, even if I retry within 1 second of failure, so it might be that the clipboard is just being used in the background by other windows processes very momentarily. |
So if we were to adjust Pillow to pause for a moment after failure and then try again, do you think that would be sufficient to resolve this? |
I think that would! It is what I am currently doing for my program, to try until it works for a certain number of iterations |
Ok, I've created PR #7141 to resolve this. If you could test it and confirm, that would be helpful. |
What did you do?
I am using the following code snippet to copy the image from clipboard whenever the application (built using FastAPI) receives a request to do so.
What did you expect to happen?
For it to get the image currently copied in the clipboard.
What actually happened?
It works fine most of the time, however it will randomly give the following error
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: