Hi Justin!

On 24 Sep., 00:04, "Justin C. Walker" <jus...@mac.com> wrote:
> For most unix-like systems, it's generally not true that a close() of a file 
> descriptor will wait until the file is closed.

Thank you, that's good to know! Then it  seems more than likely to me
that there's the problem with the expect interface.

> > Would it make sense to call os.fsync(F) after F.close()?
>
> I would think that doing this will only cause an error of some sort to be 
> handed to your code: 'F' is not associated with anything after the close, so 
> "os.sync(F)" would be essentially meaningless to the kernel.

Sure, I meant to catch the ValueError that is raised when the file
really is done.

But do I understand correctly that os.sync(F) will either raise a
ValueError orr wait until F.close() is completed?

> To your problem with corruption, if you are opening a new file descriptor for 
> a file that you are writing with an existing file descriptor, you are asking 
> for trouble, ...

It is not *I* who is asking for trouble here: The code that I posted
above is from sage/interfaces/expect.py.

>    You write to the file descriptor
>      Python holds onto the data for a while
>    You open a new descriptor on the same file
>      Python reads in what's there

I guess that is exactly what's happening in the Gap, Singular,...
interfaces:

- If one has a big string s, then singular(s) will not directly send s
to the singular interface, but eventually
singular._eval_line_using_file(s) is called.In that method, the file
singular._local_tmpfile() is opened for writing, s is written to it,
then it is closed.
- Directly after closing the file, it is read into Singular. I could
imagine that sometimes it is attempted to read it before closing it
succeeded.
- Moreover, if the next large input line occurs, then
singular._local_tmpfile() is again opened for writing -- perhaps
before the previous I/O to it was completed?


> I don't know enough about the rest of the system or your code to be sure this 
> is what's happening.  If you haven't already, try F.sync() (or os.sync(F)) 
> before closing the file.

So, better before than afterwards. Makes sense.

> Another hack: try pausing before accessing the file after the close, so 
> you're (more) sure that the close has had an effect before proceeding.

I doubt that it would be acceptable to slow down every single call to
an expect interface by pausing.

Best regards,
Simon

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

Reply via email to