From 832da418df16121ce22c0112ce276f36fa805a1a Mon Sep 17 00:00:00 2001 From: richardsheridan Date: Sat, 11 Mar 2023 00:45:07 -0500 Subject: [PATCH] unnest unprotected_fn --- trio/_threads.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/trio/_threads.py b/trio/_threads.py index 1ce9fb03fb..5556e50538 100644 --- a/trio/_threads.py +++ b/trio/_threads.py @@ -100,24 +100,23 @@ class RunSync: context = attr.ib() queue = attr.ib(init=False, factory=stdlib_queue.SimpleQueue) - def run_sync(self): - @disable_ki_protection - def unprotected_fn(): - ret = self.fn(*self.args) + @disable_ki_protection + def unprotected_fn(self): + ret = self.fn(*self.args) - if inspect.iscoroutine(ret): - # Manually close coroutine to avoid RuntimeWarnings - ret.close() - raise TypeError( - "Trio expected a sync function, but {!r} appears to be " - "asynchronous".format(getattr(self.fn, "__qualname__", self.fn)) - ) + if inspect.iscoroutine(ret): + # Manually close coroutine to avoid RuntimeWarnings + ret.close() + raise TypeError( + "Trio expected a sync function, but {!r} appears to be " + "asynchronous".format(getattr(self.fn, "__qualname__", self.fn)) + ) - return ret + return ret + def run_sync(self): self.context.run(current_async_library_cvar.set, "trio") - - result = outcome.capture(self.context.run, unprotected_fn) + result = outcome.capture(self.context.run, self.unprotected_fn) self.queue.put_nowait(result)