async def abort_handler(event_data):
# Called when ABORTING event occurs
Actor.log.info(">>> Aborting: do cleanup and save state here.")
# For example: save state
await Actor.set_value("partial_state", {"progress": 123})
# Optionally exit
await Actor.exit(status_message="Aborted by user, cleaned up", exit_code=0)
async def main() -> None:
"""
The main coroutine is being executed using asyncio.run()asyncio.run(), so do not attempt to make a normal function
out of it, it will not work. Asynchronous execution is required for communication with Apify platform,
and it also enhances performance in the field of web scraping significantly.
"""
async with Actor:
# Read the Actor input
actor_input = await Actor.get_input() or {}
Keyword_val = actor_input.get('Keyword')
# Register the abort handler
Actor.on(Event.ABORTING, abort_handler)