Re: [sage-devel] Python 3 and flushing output from external libraries

2019-09-09 Thread John H Palmieri


On Monday, September 9, 2019 at 2:06:21 PM UTC-7, Jeroen Demeyer wrote:
>
> On Mon, Sep 9, 2019 at 7:51 PM John H Palmieri  > wrote: 
> > I am writing to ask for help fixing a Python 3 problem. On some 
> platforms, there are Python 3 doctest failures in 
> > 
> > - libs/eclib/interface.py (#28454) 
>
> I believe that this has been fixed upstream, it has certainly been 
> reported by me. Are we using the latest eclib version? 
>

John Cremona is part of the discussion at #28454, and I assume he knows the 
current state of eclib. I'll let him speak to this.


> > How do we fix this? Note that patching FLINT is not ideal, since it 
> won't help users who are using the system's version of the library. FLINT's 
> most recent release was in 2015, so I don't know how much we can expect 
> from upstream regarding new releases. So maybe the ideal solution would be 
> to get Python to flush the output from these external libraries. I don't 
> know how to do this; can anyone else help? 
>
> Ideally, the upstream library should properly flush when producing 
> output. They should use fflush (in C) or std::endl or std::flush (in 
> C++). 


I can confirm that patching flint to use fflush fixes the problem, and 
similarly for eclib. Patching is not ideal, though, since we are trying to 
move to better support libraries installed system-wide. 
 

> I guess that Sage could also do the flushing whenever we return 
> from a library API call. 
>

Sounds okay to me, but I don't know how to do it. My impression is that 
`sys.stdout.flush()` just flushes Python output, not output coming from 
external libraries.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/4df27a03-a625-47bb-ad4c-f2580f4b1298%40googlegroups.com.


Re: [sage-devel] Python 3 and flushing output from external libraries

2019-09-09 Thread Jeroen Demeyer
On Mon, Sep 9, 2019 at 7:51 PM John H Palmieri  wrote:
> I am writing to ask for help fixing a Python 3 problem. On some platforms, 
> there are Python 3 doctest failures in
>
> - libs/eclib/interface.py (#28454)

I believe that this has been fixed upstream, it has certainly been
reported by me. Are we using the latest eclib version?

> How do we fix this? Note that patching FLINT is not ideal, since it won't 
> help users who are using the system's version of the library. FLINT's most 
> recent release was in 2015, so I don't know how much we can expect from 
> upstream regarding new releases. So maybe the ideal solution would be to get 
> Python to flush the output from these external libraries. I don't know how to 
> do this; can anyone else help?

Ideally, the upstream library should properly flush when producing
output. They should use fflush (in C) or std::endl or std::flush (in
C++). I guess that Sage could also do the flushing whenever we return
from a library API call.

> I'm also curious about what's causing the problem. Is it a bug in Python 3?

It's just a completely different implementation of I/O, independent of
the C standard I/O library (Python 2 uses the  functionality)

> Why does it only appear on some platforms?

I don't think it should be platform-dependent. Let's not focus on this too much.

PS: apologies for the quick and short email, I need to sleep ;-)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CALZ1QMq96G7RL1cRONNKSUx4KVt%2B6Ni6V%2BzC%3DN3cxyGCB1YkCA%40mail.gmail.com.


[sage-devel] Python 3 and flushing output from external libraries

2019-09-09 Thread John H Palmieri
I am writing to ask for help fixing a Python 3 problem. On some platforms, 
there are Python 3 doctest failures in

- libs/eclib/interface.py (#28454)
- rings/polynomial/polynomial_rational_flint.pyx (#28334)

and both occur for the same reason: warning messages printed by C or C++ 
libraries are not appearing when they are supposed to, but rather some time 
later. So for example, in

 FLINT memory errors do not crash Sage (:trac:`17629`)::

 sage: t^(sys.maxsize//2)
 Traceback (most recent call last):
 ...
 RuntimeError: FLINT exception

the "..." should capture a message "Exception (FLINT memory_manager). 
Unable to allocate memory", and when you run it from the command line, this 
message appears. When running doctests, though, with Python 3 only and on 
some platforms only (debian, ubuntu — don't know why), this message only 
pops up at some later time, leading to this:

Failed example:
   G = f.galois_group(); G
Expected:
   Transitive group number 5 of degree 4
Got:
   Exception (FLINT memory_manager). Unable to allocate memory.
   Transitive group number 5 of degree 4


The `f.galois_group()` command has nothing to do with this error, but something 
about it triggers the old output to be flushed.

How do we fix this? Note that patching FLINT is not ideal, since it won't 
help users who are using the system's version of the library. FLINT's most 
recent release was in 2015, so I don't know how much we can expect from 
upstream regarding new releases. So maybe the ideal solution would be to 
get Python to flush the output from these external libraries. I don't know 
how to do this; can anyone else help?


I'm also curious about what's causing the problem. Is it a bug in Python 3? If 
not, is this change in behavior documented anywhere? Why does it only appear on 
some platforms?

-- 
John

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/6e394ce1-5c04-40a9-8f17-590a1c4f5e1b%40googlegroups.com.