55
55
class _ActorType :
56
56
"""The class of `Actor`. Only make a new instance if you're absolutely sure you need to."""
57
57
58
- _apify_client : ApifyClientAsync
59
- _configuration : Configuration
60
- _is_exiting = False
61
58
_is_rebooting = False
59
+ _is_any_instance_initialized = False
62
60
63
61
def __init__ (
64
62
self ,
@@ -76,6 +74,8 @@ def __init__(
76
74
be created.
77
75
configure_logging: Should the default logging configuration be configured?
78
76
"""
77
+ self ._is_exiting = False
78
+
79
79
self ._configuration = configuration or Configuration .get_global_configuration ()
80
80
self ._configure_logging = configure_logging
81
81
self ._apify_client = self .new_client ()
@@ -200,6 +200,12 @@ async def init(self) -> None:
200
200
if self ._is_initialized :
201
201
raise RuntimeError ('The Actor was already initialized!' )
202
202
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
+
203
209
self ._is_exiting = False
204
210
self ._was_final_persist_state_emitted = False
205
211
@@ -223,6 +229,7 @@ async def init(self) -> None:
223
229
await self ._event_manager .__aenter__ ()
224
230
225
231
self ._is_initialized = True
232
+ _ActorType ._is_any_instance_initialized = True
226
233
227
234
async def exit (
228
235
self ,
@@ -898,11 +905,11 @@ async def reboot(
898
905
self .log .error ('Actor.reboot() is only supported when running on the Apify platform.' )
899
906
return
900
907
901
- if self ._is_rebooting :
908
+ if _ActorType ._is_rebooting :
902
909
self .log .debug ('Actor is already rebooting, skipping the additional reboot call.' )
903
910
return
904
911
905
- self ._is_rebooting = True
912
+ _ActorType ._is_rebooting = True
906
913
907
914
if not custom_after_sleep :
908
915
custom_after_sleep = self ._configuration .metamorph_after_sleep
0 commit comments