You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m working with Thespian (version 3.10) and found a limitation that could simplify actor initialization. When creating an actor using createActor, it’s currently not possible to pass arguments directly to the actor’s constructor (__init__). Instead, initialization often needs to be handled via messages after the actor is created or by manually setting defaults and checking for uninitialized values in receiveMessage.
Current Approach
For actors that require specific initialization values (like configuration parameters or dependencies), we are forced to handle this in one of two ways:
Send an initialization message immediately after creating the actor.
Set default values and manually reinitialize the actor upon receiving its first message.
This can be cumbersome for actors with complex initialization requirements.
Request
I propose adding support for passing constructor arguments (e.g., via initArgs) when calling createActor. This would enable more seamless actor creation by allowing the following:
Internally, the actor’s __init__ method would be called with the supplied arguments (arg1, arg2, etc.), allowing for direct actor initialization.
This approach is similar to the withPossibleInitArgs utility that selectively passes arguments to the constructor based on the class’s __init__ signature.
Example Implementation
Here’s a similar concept using withPossibleInitArgs for class initialization:
Cleaner Initialization: By directly supporting constructor arguments, actors can be initialized in a cleaner, more Pythonic manner without needing to send an extra message for initialization.
Improved Flexibility: This would allow actors to receive dependencies or configurations at creation time, simplifying the process for both developers and the system.
Is this feature already on the roadmap, or would it be something you’d consider adding in future versions?
Thanks for your consideration!
The text was updated successfully, but these errors were encountered:
I had intentionally not provided the ability to pass arguments to Actor constructors due to several concerns about supporting this. I'll provide an overview of the concerns here preparatory to adding them to the main documentation.
Remote Actors
When actors are created on remote systems, the arguments to the constructor would need to be passed to that remote system, which implies the ability to marshal, transmit, and reconstitute those arguments by the local and remote Admin, which adds complexities and associated concerns to the Admin.
Initialization argument longevity.
Admins will restart failed Actors, so the initialization values would need to be stable for the potential lifetime of the Actor System.
Actor initialization activities
Another concern is the activities performed by the actor with these initialization arguments. At constructor time, the Actor is not fully established as a functioning Actor, and therefore does not have the normal message generation and response capabilities yet. Thus, there would need to be a lot of documentation and possibly active protection against a constructor sending messages or doing other interactions with other elements.
Hello Thespian team,
I’m working with Thespian (version 3.10) and found a limitation that could simplify actor initialization. When creating an actor using
createActor
, it’s currently not possible to pass arguments directly to the actor’s constructor (__init__
). Instead, initialization often needs to be handled via messages after the actor is created or by manually setting defaults and checking for uninitialized values inreceiveMessage
.Current Approach
For actors that require specific initialization values (like configuration parameters or dependencies), we are forced to handle this in one of two ways:
This can be cumbersome for actors with complex initialization requirements.
Request
I propose adding support for passing constructor arguments (e.g., via
initArgs
) when callingcreateActor
. This would enable more seamless actor creation by allowing the following:Internally, the actor’s
__init__
method would be called with the supplied arguments (arg1
,arg2
, etc.), allowing for direct actor initialization.This approach is similar to the
withPossibleInitArgs
utility that selectively passes arguments to the constructor based on the class’s__init__
signature.Example Implementation
Here’s a similar concept using
withPossibleInitArgs
for class initialization:Benefits:
Is this feature already on the roadmap, or would it be something you’d consider adding in future versions?
Thanks for your consideration!
The text was updated successfully, but these errors were encountered: