Skip to content

refactor!: Use one EventManager per process, started on first use - #2492

Open
Mantisus wants to merge 1 commit into
apify:v2from
Mantisus:single-event-manager
Open

Mantisus wants to merge 1 commit into
apify:v2from
Mantisus:single-event-manager

Conversation

@Mantisus

@Mantisus Mantisus commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • The whole process shares one event manager. It starts on the first on() or emit() call and closes with its event loop, emitting a final PERSIST_STATE event.
  • The event_manager argument is removed from crawlers, SessionPool and ServiceLocator. A crawler no longer enters the event manager and emits a PERSIST_STATE event at the end of every run instead.
  • A request queue, a RequestList or a use_state dictionary used outside a crawler now saves its state periodically.
  • A custom event manager that has to await something to start sets supports_lazy_start = False and has to be entered before anything registers a listener.
  • With a storage backend closed before the event loop ends, such as a SqlStorageBackend used with async with, a use_state dictionary logs a warning at the shutdown that its last save failed. The state saved at the end of the run stays in the store.

Issues

Testing

  • Unit tests for the lazy start, closing with the event loop, managers that don't start by themselves, a forked child process, the order of the final PERSIST_STATE event and the end of a crawler run.

✍️ Drafted by Claude Code

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 22, 2026
@Mantisus Mantisus self-assigned this Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant