5555class _ActorType :
5656 """The class of `Actor`. Only make a new instance if you're absolutely sure you need to."""
5757
58- _apify_client : ApifyClientAsync
59- _configuration : Configuration
60- _is_exiting = False
6158 _is_rebooting = False
59+ _is_any_instance_initialized = False
6260
6361 def __init__ (
6462 self ,
@@ -76,6 +74,8 @@ def __init__(
7674 be created.
7775 configure_logging: Should the default logging configuration be configured?
7876 """
77+ self ._is_exiting = False
78+
7979 self ._configuration = configuration or Configuration .get_global_configuration ()
8080 self ._configure_logging = configure_logging
8181 self ._apify_client = self .new_client ()
@@ -200,6 +200,12 @@ async def init(self) -> None:
200200 if self ._is_initialized :
201201 raise RuntimeError ('The Actor was already initialized!' )
202202
203+ if _ActorType ._is_any_instance_initialized :
204+ self .log .warning ('Repeated Actor initialization detected - this is non-standard usage, proceed with care' )
205+
206+ # Make sure that the currently initialized instance is also available through the global `Actor` proxy
207+ cast (Proxy , Actor ).__wrapped__ = self
208+
203209 self ._is_exiting = False
204210 self ._was_final_persist_state_emitted = False
205211
@@ -223,6 +229,7 @@ async def init(self) -> None:
223229 await self ._event_manager .__aenter__ ()
224230
225231 self ._is_initialized = True
232+ _ActorType ._is_any_instance_initialized = True
226233
227234 async def exit (
228235 self ,
@@ -898,11 +905,11 @@ async def reboot(
898905 self .log .error ('Actor.reboot() is only supported when running on the Apify platform.' )
899906 return
900907
901- if self ._is_rebooting :
908+ if _ActorType ._is_rebooting :
902909 self .log .debug ('Actor is already rebooting, skipping the additional reboot call.' )
903910 return
904911
905- self ._is_rebooting = True
912+ _ActorType ._is_rebooting = True
906913
907914 if not custom_after_sleep :
908915 custom_after_sleep = self ._configuration .metamorph_after_sleep
0 commit comments