Skip to content

Commit

Permalink
If the clipboard fails to open on Windows, wait and try again
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 8, 2023
1 parent 2a274a4 commit f67fcf1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,14 @@ PyImaging_GrabClipboardWin32(PyObject *self, PyObject *args) {
LPCSTR format_names[] = {"DIB", "DIB", "file", "png", NULL};

if (!OpenClipboard(NULL)) {
PyErr_SetString(PyExc_OSError, "failed to open clipboard");
return 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
Expand Down

0 comments on commit f67fcf1

Please sign in to comment.