Hi Ryan!

On 24 Sep., 18:13, Ryan Hinton <[email protected]> wrote:
> Have you considered Python's tempfile module?
>
> http://docs.python.org/library/tempfile.html

No, I didn't, yet.

Since the different Gap instances in the parallelised function have
different pid, it would solve the problem to make the _local_tmpfile
dependent on the pid:

sage: @parallel
....: def f(n):
....:     return gap.pid()
....:
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/20166//interface//tmp20222
sage: L = [t[1] for t in f(range(5))]
sage: len(set(L))
5

So, a viable solution would be to define
    def _local_tmpfile(self):
        return '%s/tmp'%SAGE_TMP_INTERFACE + str(self.pid())

However, for efficiency reasons, the current _local_tmpfile method
caches the result, using an attribute __local_tmpfile (double
underscore). I tried to do the same. With printing some debugging
information, I did

    def _local_tmpfile(self):
        try:
            out = self.__local_tmpfile
            print 'have local tmpfile'
            return out
        except AttributeError:
            self.__local_tmpfile = '%s/tmp'%SAGE_TMP_INTERFACE +
str(self.pid())
            return self.__local_tmpfile

With that definition, one obtains

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/20333//interface//tmp20360
sage: L = [t[1] for t in f(range(5))]
have local tmpfile
have local tmpfile
have local tmpfile
have local tmpfile
have local tmpfile
sage: gap.__local_tmpfile
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)
...
AttributeError:
sage: print gap._local_tmpfile()
have local tmpfile
/home/king/.sage//temp/gauss/20333//interface//tmp20360

%%%%%%%%%%%%%%%%%%%%

Now I wonder:

* Why do the gap instances in the parallelised method inherit the
attribute __local_tmpfile from the gap instance of the main sage
process? Note that they do not inherit the pid!
* Why is it not possible to access gap.__local_tmpfile, even though
this attribute *can* be accessed from inside the method?

The Expect interfaces seem to have a  custom __setattr__, but I can
not find its definition:

sage: from sage.interfaces.expect import Expect
sage: Expect.__setattr__??
Error getting source: arg is not a module, class, method, function,
traceback, frame, or code object
Type:           wrapper_descriptor
Base Class:     <type 'wrapper_descriptor'>
String Form:    <slot wrapper '__setattr__' of 'object' objects>
Namespace:      Interactive
Docstring [source file open failed]:
    x.__setattr__('name', value) <==> x.name = value


Could it be that, when doing
    self.__local_tmpfile = '%s/tmp'%SAGE_TMP_INTERFACE +
str(self.pid())
inside the method, __setattr__ associates this attribute with the
*class* sage.interfaces.gap.Gap, rather than with only a single
instance of that class?

Cheers,
Simon

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