mit einem Klick
handling-cancellation
// Handle graceful cancellation in inference.sh apps. Use when implementing long-running tasks that users might cancel.
// Handle graceful cancellation in inference.sh apps. Use when implementing long-running tasks that users might cancel.
Configure inf.yml for inference.sh apps. Use when setting GPU, VRAM, RAM, categories, environment variables, packages.txt, or resource requirements.
Debug and troubleshoot inference.sh apps. Use when facing import errors, CUDA issues, memory problems, or deployment failures.
Handle API keys and sensitive values in inference.sh apps. Use when adding secrets, accessing environment variables, or securing credentials.
Optimize inference.sh app performance. Use when handling memory, devices, model loading, mixed precision, or flash attention.
Build and deploy applications on inference.sh. Use when getting started, understanding the platform, or needing an overview of inference.sh development.
Track usage with output metadata in inference.sh apps. Use when implementing billing, counting tokens, or reporting image/video/audio generation metrics.
| name | handling-cancellation |
| description | Handle graceful cancellation in inference.sh apps. Use when implementing long-running tasks that users might cancel. |
Handle user cancellation for long-running tasks.
class App(BaseApp):
async def setup(self, config):
self.cancel_flag = False
async def on_cancel(self):
"""Called when user cancels - must return quickly"""
self.cancel_flag = True
return True
async def run(self, input):
self.cancel_flag = False
for i in range(100):
if self.cancel_flag:
print("Stopping work...")
break
await self.heavy_computation(i)
on_cancel must be fast (just set flag)📖 Full docs: inference.sh/docs/extend/cancellation