mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 07:16:31 +01:00
Avoid inf recursion when deleting script from at_stop. Resolve #2642
This commit is contained in:
parent
c4a005e64a
commit
970f067a6f
2 changed files with 13 additions and 12 deletions
|
|
@ -3373,7 +3373,7 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
|
|||
obj_query = script_query = self.args
|
||||
|
||||
scripts = self._search_script(script_query)
|
||||
objects = ObjectDB.objects.object_search(obj_query)
|
||||
objects = caller.search(obj_query, quiet=True)
|
||||
obj = objects[0] if objects else None
|
||||
|
||||
if not self.switches:
|
||||
|
|
@ -3461,7 +3461,10 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
|
|||
)
|
||||
caller.msg("\n".join(msgs))
|
||||
if "delete" not in self.switches:
|
||||
ScriptEvMore(caller, [script], session=self.session)
|
||||
if script and script.pk:
|
||||
ScriptEvMore(caller, [script], session=self.session)
|
||||
else:
|
||||
caller.msg("Script was deleted automatically.")
|
||||
else:
|
||||
caller.msg("No scripts found.")
|
||||
|
||||
|
|
|
|||
|
|
@ -316,9 +316,12 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
|||
Stop task runner and delete the task.
|
||||
|
||||
"""
|
||||
task_stopped = False
|
||||
task = self.ndb._task
|
||||
if task and task.running:
|
||||
task.stop()
|
||||
task_stopped = True
|
||||
|
||||
self.ndb._task = None
|
||||
self.db_is_active = False
|
||||
|
||||
|
|
@ -328,7 +331,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
|||
self.db._manually_paused = None
|
||||
|
||||
self.save(update_fields=["db_is_active"])
|
||||
self.at_stop(**kwargs)
|
||||
if task_stopped:
|
||||
self.at_stop(**kwargs)
|
||||
|
||||
def _step_errback(self, e):
|
||||
"""
|
||||
|
|
@ -449,17 +453,11 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
|||
# autostart the script
|
||||
self._start_task(force_restart=True)
|
||||
|
||||
def delete(self, stop_task=True):
|
||||
def delete(self):
|
||||
"""
|
||||
Delete the Script. Normally stops any timer task. This fires at_script_delete before
|
||||
deletion.
|
||||
|
||||
Args:
|
||||
stop_task (bool, optional): If unset, the task will not be stopped
|
||||
when this method is called. The main reason for setting this to False
|
||||
is if wanting to delete the script from the at_stop method - setting
|
||||
this will then avoid an infinite recursion.
|
||||
|
||||
Returns:
|
||||
bool: If deletion was successful or not. Only time this can fail would be if
|
||||
the script was already previously deleted, or `at_script_delete` returns
|
||||
|
|
@ -468,8 +466,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
|||
"""
|
||||
if not self.pk or not self.at_script_delete():
|
||||
return False
|
||||
if stop_task:
|
||||
self._stop_task()
|
||||
|
||||
self._stop_task()
|
||||
super().delete()
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue