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:
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: