Hi all!

On 24 Sep., 20:39, "Justin C. Walker" <[email protected]> wrote:
> The fact that all (or some) instances use the same file make it a  
> race condition for sure.  It's just that in this case, there may be a  
> very simple fix for it (Ryan's suggestion of using distinct temp  
> files, for example).

Well, apparently there is an easy fix. But it is not clear if this is
efficient enough. Caching seems to be a good idea, but in fact caching
probably is the ultimate cause of the problem.

I'd like to get peoples opinion:
  Expect._local_tmpfile() is called frequently (namely every time a
long command is sent through the interface). Do you think it is
imperative to cache the method?

BUT: If you believe that caching is important then please explain why
caching fails, as shown below; and please answer the questions on
accessibility of the attribute self.__local_tmpfile that I asked in a
previous post! Is there any nasty stuff going on with __setattr__/
__getattr__?

Cheers,
Simon

EXAMPLES:

(1) The easy fix, without caching

Define
    def _local_tmpfile(self):
        return '%s/tmp'%SAGE_TMP_INTERFACE + str(self.pid())

Then things work:
sage: @parallel
....: def f(n):
....:     return gap._local_tmpfile()
....:
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
5
sage: print gap._local_tmpfile()
/home/king/.sage//temp/gauss/21765//interface//tmp21792
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
5

2) Several ways of caching fail -- but why???

Define
    def _local_tmpfile(self):
        try:
            return self.__local_tmpfile
        except AttributeError:
            self.__local_tmpfile = '%s/tmp'%SAGE_TMP_INTERFACE +
str(self.pid())
            return self.__local_tmpfile

Then things fail:
sage: @parallel
....: def f(n):
....:     return gap._local_tmpfile()
....:
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
5
sage: print gap._local_tmpfile()
/home/king/.sage//temp/gauss/21921//interface//tmp21948
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
1

Or define
    @lazy_attribute
    def _local_tmpfile(self):
        return '%s/tmp'%SAGE_TMP_INTERFACE + str(self.pid())

Then, one still gets (dropping the brackets after _local_tmpfile)
sage: @parallel
....: def f(n):
....:     return gap._local_tmpfile
....:
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
5
sage: print gap._local_tmpfile
/home/king/.sage//temp/gauss/22488//interface//tmp22515
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
1

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to