Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
class _ActorType:
"""The class of `Actor`. Only make a new instance if you're absolutely sure you need to."""

_apify_client: ApifyClientAsync
_configuration: Configuration
_is_exiting = False
_is_rebooting = False

def __init__(
Expand All @@ -76,6 +73,8 @@ def __init__(
be created.
configure_logging: Should the default logging configuration be configured?
"""
self._is_exiting = False

self._configuration = configuration or Configuration.get_global_configuration()
self._configure_logging = configure_logging
self._apify_client = self.new_client()
Expand Down Expand Up @@ -200,6 +199,9 @@ async def init(self) -> None:
if self._is_initialized:
raise RuntimeError('The Actor was already initialized!')

# Make sure that the currently initialized instance is also available through the global `Actor` proxy
cast(Proxy, Actor).__wrapped__ = self

self._is_exiting = False
self._was_final_persist_state_emitted = False

Expand Down Expand Up @@ -898,11 +900,11 @@ async def reboot(
self.log.error('Actor.reboot() is only supported when running on the Apify platform.')
return

if self._is_rebooting:
if _ActorType._is_rebooting:
self.log.debug('Actor is already rebooting, skipping the additional reboot call.')
return

self._is_rebooting = True
_ActorType._is_rebooting = True

if not custom_after_sleep:
custom_after_sleep = self._configuration.metamorph_after_sleep
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/actor/test_actor_non_default_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ async def test_actor_with_non_default_config() -> None:

async with Actor(config) as actor:
assert actor.config.internal_timeout == timedelta(minutes=111)


async def test_actor_global_works() -> None:
non_default_configuration = Configuration(actor_full_name='Actor McActorson, esq.')

async with Actor(configuration=non_default_configuration):
assert Actor.configuration is non_default_configuration