Skip to content

Commit

Permalink
Merge pull request #236 from googlefonts/watchfiles-workaround
Browse files Browse the repository at this point in the history
On exit, suppress a buggy exception from watchfiles
  • Loading branch information
justvanrossum authored Jan 30, 2023
2 parents 83effe3 + 667f8f3 commit f42d8dc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/fontra/core/fonthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __post_init__(self):
async def startTasks(self):
if hasattr(self.backend, "watchExternalChanges"):
self._watcherTask = asyncio.create_task(self.processExternalChanges())
self._watcherTask.add_done_callback(taskDoneHelper)
self._watcherTask.add_done_callback(taskDoneHelperWatchFiles)
self._processWritesError = None
self._processWritesEvent = asyncio.Event()
self._processWritesTask = asyncio.create_task(self.processWrites())
Expand Down Expand Up @@ -468,6 +468,16 @@ def taskDoneHelper(task):
)


def taskDoneHelperWatchFiles(task):
if not task.cancelled() and task.exception() is not None:
exception = task.exception()
if isinstance(exception, RuntimeError) and str(exception) == "Already borrowed":
# Suppress RuntimeError("Already borrowed"), to work around this watchfiles
# issue: https://github.com/samuelcolvin/watchfiles/issues/200
return
logger.exception(f"fatal exception in asyncio task {task}", exc_info=exception)


def _writeKeyToPattern(writeKey):
if not isinstance(writeKey, tuple):
writeKey = (writeKey,)
Expand Down

0 comments on commit f42d8dc

Please sign in to comment.