Skip to content

Commit

Permalink
unnest unprotected_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
richardsheridan committed Mar 11, 2023
1 parent 2b088cc commit 832da41
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions trio/_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 832da41

Please sign in to comment.