Skip to content

Commit

Permalink
✨Supported no_offload
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed May 30, 2023
1 parent 9c2c621 commit 8cb2fc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cfdraw/app/endpoints/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ async def run(self) -> None:
try:
plugin.elapsed_times.start()
if await self._broadcast_working(uid):
await offload(plugin(request))
future = plugin(request)
if not plugin.settings.no_offload:
future = offload(future)
await future
except Exception as err:
await self._broadcast_exception(uid, get_err_msg(err))
# cleanup
Expand Down
10 changes: 10 additions & 0 deletions cfdraw/schema/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ class IPluginSettings(IChakra):
None,
description="Extra (chakra) props of the plugin button",
)
# internal fields
no_offload: bool = Field(
False,
description=(
"Whether not to offload the plugin to sub-thread when it is executed, "
"useful when you know the plugin is fast enough.\n"
"> This is introduced mainly because some libraries (e.g., `matplotlib`) "
"need to be executed in the main thread."
),
)

def to_react(self, type: str, hash: str, identifier: str) -> Dict[str, Any]:
d = self.dict(exclude={"pluginInfo"})
Expand Down

0 comments on commit 8cb2fc8

Please sign in to comment.