Skip to content

Constructor _ActorType.__init__ is being executed twice #397

@vdusek

Description

@vdusek

Description

The _ActorType.__init__ constructor is executed twice when creating an instance of Actor.

Reproduction

I added simple prints to the _ActorType.__init__, _ActorType.__aenter__ and _ActorType.init methods and prepared a simple Actor:

from apify import Actor

async def main() -> None:
    async with Actor() as actor:
        actor.log.info(f'Hello! Actor={Actor}, actor={actor}.')

Execution:

$ apify run
Run: /home/vdusek/Projects/apify-sdk-python/.venv/bin/python3 -m src
Hello from _ActorType.__init__
Hello from _ActorType.__init__
Hello from _ActorType.__aenter__
Hello from _ActorType.init
[apify] INFO  Initializing Actor...
[apify] INFO  System info ({"apify_sdk_version": "2.2.2", "apify_client_version": "1.8.1", "crawlee_version": "0.5.3", "python_version": "3.13.2", "os": "linux"})
[apify] INFO  Hello! Actor=<apify.Actor>, actor=<apify._actor._ActorType object at 0x7ff7f757fed0>.
[apify] INFO  Exiting Actor ({"exit_code": 0})

This does not happen when using the Actor class without an instance, as shown below:

from apify import Actor

async def main() -> None:
    async with Actor:
        Actor.log.info(f'Hello! Actor={Actor}.')

Output

$ apify run
Run: /home/vdusek/Projects/apify-sdk-python/.venv/bin/python3 -m src
Hello from _ActorType.__init__
Hello from _ActorType.__aenter__
Hello from _ActorType.init
[apify] INFO  Initializing Actor...
[apify] INFO  System info ({"apify_sdk_version": "2.2.2", "apify_client_version": "1.8.1", "crawlee_version": "0.5.3", "python_version": "3.13.2", "os": "linux"})
[apify] INFO  Hello! Actor=<apify.Actor>.
[apify] INFO  Exiting Actor ({"exit_code": 0})

Metadata

Metadata

Assignees

Labels

bugSomething isn't working.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions