flash mage
flash mage3w ago

i face problem when listen abort event [python sdk]

I followed the official documentation's template code to implement an Apify Actor, built and deployed it on the Apify platform. When I run the Actor and click Abort (graceful abort), the ABORTING event handler handler_foo does not log anything — Actor.log.info(...) inside it never appears. I have no way to confirm whether the handler is actually being triggered, and I need to perform custom actions when the user aborts the run. Questions: How can I guarantee that the ABORTING event handler is called? How can I ensure that logs and operations (like Actor.set_value) inside it execute and appear in the logs? -------------------------------------------------------------------------------------------- from apify import Actor from apify_shared.consts import ActorEventTypes import asyncio def handler_foo(arg: dict): Actor.log.info(f'handler_foo: arg = {arg}') def handler_boo(arg: dict): pass async def main(): async with Actor: # Add event handler Actor.on(ActorEventTypes.ABORTING, handler_foo) await asyncio.sleep(5*1000) # Remove all handlers for a specific event Actor.off('systemInfo') # Remove a specific event handler Actor.off('systemInfo', handler_boo)
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?