From fdb7452f5b3bed85df7f133df95b66b509f25f8f Mon Sep 17 00:00:00 2001 From: wstein Date: Sun, 4 May 2008 10:04:33 -0700 Subject: [PATCH] trac #3098 -- issues with synchronizing the singular interface --- src/sage/interfaces/singular.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index 1996c624813..d25cf0dc295 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -314,6 +314,7 @@ def __init__(self, maxread=1000, script_subdirectory=None, eval_using_file_cutoff=1000) self.__libs = [] self._prompt_wait = prompt + self.__to_clear = [] # list of variable names that need to be cleared. def _start(self, alt_message=None): self.__libs = [] @@ -404,7 +405,14 @@ def eval(self, x, allow_semicolon=True, strip=True): sage: o = s.hilb() """ + # Syncrhonize the interface and clear any variables that are queued up to + # be cleared. self._synchronize() + if len(self.__to_clear) > 0: + for var in self.__to_clear: + self._eval_line('if(defined(%s)>0){kill %s;};'%(var,var), wait_for_prompt=False) + self.__to_clear = [] + self._synchronize() # Uncomment the print statements below for low-level debuging of # code that involves the singular interfaces. Everything goes @@ -451,7 +459,12 @@ def clear(self, var): """ Clear the variable named var. """ - self._eval_line('if(defined(%s)>0){kill %s;};'%(var,var), wait_for_prompt=False) + # We add the variable to the list of vars to clear when we do an eval. + # We queue up all the clears and do them at once to avoid synchronizing + # the interface at the same time we do garbage collection, which can + # lead to subtle problems. This was Willem Jan's ideas, implemented + # by William Stein. + self.__to_clear.append(var) def _create(self, value, type='def'): name = self._next_var_name()