Pyhon SDK on Aborting
I am trying to catch ABORTING event with the following code, without success. Could someone teach me how to do it properly ? Thanks
the
import asyncio
from apify import Actor
from apify.consts import ActorEventTypes
async def on_abort(event_data):
print('### ABORTED', event_data)
async def main():
async with Actor:
print('INIT')
Actor.on(ActorEventTypes.ABORTING, on_abort)
print('sleeping ...')
await asyncio.sleep(10) ## PRESS ABORT
actor_input = await Actor.get_input()
print(actor_input)
print('DONE')
if __name__ == '__main__':
asyncio.run(main())import asyncio
from apify import Actor
from apify.consts import ActorEventTypes
async def on_abort(event_data):
print('### ABORTED', event_data)
async def main():
async with Actor:
print('INIT')
Actor.on(ActorEventTypes.ABORTING, on_abort)
print('sleeping ...')
await asyncio.sleep(10) ## PRESS ABORT
actor_input = await Actor.get_input()
print(actor_input)
print('DONE')
if __name__ == '__main__':
asyncio.run(main())the
on_aborton_abort function never called, this is the output:2023-04-05T19:03:20.022Z ACTOR: Pulling Docker image from repository.
2023-04-05T19:03:20.191Z ACTOR: Creating Docker container.
2023-04-05T19:03:20.324Z ACTOR: Starting Docker container.
2023-04-05T19:03:24.127Z INIT
2023-04-05T19:03:24.129Z sleeping ...
2023-04-05T19:03:28.185Z ACTOR: The actor run was aborted by the user.2023-04-05T19:03:20.022Z ACTOR: Pulling Docker image from repository.
2023-04-05T19:03:20.191Z ACTOR: Creating Docker container.
2023-04-05T19:03:20.324Z ACTOR: Starting Docker container.
2023-04-05T19:03:24.127Z INIT
2023-04-05T19:03:24.129Z sleeping ...
2023-04-05T19:03:28.185Z ACTOR: The actor run was aborted by the user.