2121from simpleflow .base import Submittable
2222from simpleflow .history import History
2323from simpleflow .signal import WaitForSignal
24- from simpleflow .swf import constants
2524from simpleflow .swf .helpers import swf_identity
2625from simpleflow .swf .task import ActivityTask , WorkflowTask , SignalTask
2726from simpleflow .task import (
@@ -151,7 +150,6 @@ class Executor(executor.Executor):
151150
152151 :ivar domain: domain
153152 :type domain: swf.models.domain.Domain
154- :ivar workflow: workflow
155153 :ivar task_list: task list
156154 :type task_list: Optional[str]
157155 :ivar repair_with: previous history to use for repairing
@@ -161,9 +159,9 @@ class Executor(executor.Executor):
161159
162160 """
163161
164- def __init__ (self , domain , workflow , task_list = None , repair_with = None ,
162+ def __init__ (self , domain , workflow_class , task_list = None , repair_with = None ,
165163 force_activities = None ):
166- super (Executor , self ).__init__ (workflow )
164+ super (Executor , self ).__init__ (workflow_class )
167165 self ._history = None
168166 self ._execution_context = {}
169167 self .domain = domain
@@ -175,6 +173,7 @@ def __init__(self, domain, workflow, task_list=None, repair_with=None,
175173 self .force_activities = None
176174 self .reset ()
177175
176+ # noinspection PyAttributeOutsideInit
178177 def reset (self ):
179178 """
180179 Clears the state of the execution.
@@ -187,6 +186,9 @@ def reset(self):
187186 self ._decisions = []
188187 self ._tasks = TaskRegistry ()
189188 self ._idempotent_tasks_to_submit = set ()
189+ self ._execution = None
190+ self .current_priority = None
191+ self .create_workflow ()
190192
191193 def _make_task_id (self , a_task , * args , ** kwargs ):
192194 """
@@ -783,6 +785,7 @@ def replay(self, decision_response):
783785 len (self ._decisions ),
784786 ))
785787 self .after_replay ()
788+ self .decref_workflow ()
786789 return self ._decisions , {}
787790 except exceptions .TaskException as err :
788791 reason = 'Workflow execution error in task {}: "{}"' .format (
@@ -799,6 +802,7 @@ def replay(self, decision_response):
799802 details = swf .format .details (details ),
800803 )
801804 self .after_closed ()
805+ self .decref_workflow ()
802806 return [decision ], {}
803807
804808 except Exception as err :
@@ -819,15 +823,23 @@ def replay(self, decision_response):
819823 details = swf .format .details (details ),
820824 )
821825 self .after_closed ()
826+ self .decref_workflow ()
822827 return [decision ], {}
823828
824829 self .after_replay ()
825830 decision = swf .models .decision .WorkflowExecutionDecision ()
826831 decision .complete (result = swf .format .result (json_dumps (result )))
827832 self .on_completed ()
828833 self .after_closed ()
834+ self .decref_workflow ()
829835 return [decision ], {}
830836
837+ def decref_workflow (self ):
838+ """
839+ Set the `_workflow` ivar to None in the hope of reducing memory consumption.
840+ """
841+ self ._workflow = None
842+
831843 def before_replay (self ):
832844 return self ._workflow .before_replay (self ._history )
833845
0 commit comments