If the clipboard fails to open on Windows, wait and try again

This commit is contained in:
Andrew Murray 2023-05-08 11:58:05 +10:00
parent 2a274a4760
commit f67fcf131a

View File

@ -436,10 +436,16 @@ PyImaging_GrabClipboardWin32(PyObject *self, PyObject *args) {
UINT formats[] = {CF_DIB, CF_DIBV5, CF_HDROP, RegisterClipboardFormatA("PNG"), 0};
LPCSTR format_names[] = {"DIB", "DIB", "file", "png", NULL};
if (!OpenClipboard(NULL)) {
// Maybe the clipboard is temporarily in use by another process.
// Wait and try again
Sleep(500);
if (!OpenClipboard(NULL)) {
PyErr_SetString(PyExc_OSError, "failed to open clipboard");
return NULL;
}
}
// find best format as set by clipboard owner
format = 0;