This should be the problem:

1. If you start singular normally, it prints version info, etc to stdout and
then waits for stdin.  So if we read stdout, we should get something
immediately after the process is started.

2. We set stdout to nonblocking (in the python process), so read() doesn't
block.

3. I ran strace to see what was happening.  For some reason singular is
trying to read from stdin before it prints anything to stdout.

relevant strace details from the python process:

{{{
pipe([3, 4])                            = 0
pipe([5, 6])                            = 0
pipe([7, 8])                            = 0
fcntl(8, F_GETFD)                       = 0
fcntl(8, F_SETFD, FD_CLOEXEC)           = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0x7f8aaf3eb9d0) = 30213
close(8)                                = 0
close(3)                                = 0
close(6)                                = 0
...
fcntl(5, F_GETFL)                       = 0 (flags O_RDONLY)
fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
read(5, 0x1a9c8a4, 4096)                = -1 EAGAIN (Resource temporarily
unavailable)
... (this read is repeated while the python process tries to read any output
from the singular process for about a second)
...
kill(30213, SIGTERM)                    = 0
...
--- SIGCHLD (Child exited) @ 0 (0) ---
...
}}}


relevant strace details from the clone()-ed singular process:

{{{
close(4)                                = 0
close(5)                                = 0
close(7)                                = 0
dup2(3, 0)                              = 0
dup2(6, 1)                              = 1
dup2(6, 2)                              = 2
close(3)                                = 0
close(6)                                = 0
execve("/home/alex/progs/src/sage-4.6.1.alpha2/local/bin/Singular-3-1-1",
["Singular-3-1-1", "-t"], [/* 81 vars */]) = 0
...
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff17936e60) = -1 EINVAL (Invalid
argument)
...
fstat(0, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7ff5da40b000
read(0, 0x7ff5da40b000, 4096)           = ? ERESTARTSYS (To be restarted)
--- SIGTERM (Terminated) @ 0 (0) ---
}}}


The above output was produced by
{{{
strace -o strace_python_singular_-t_noshell.txt -ff -F python test_Popen.py
Singular-3-1-1 -t
}}}


 - Alex

On Mon, Nov 22, 2010 at 3:02 PM, Mike Hansen <mhan...@gmail.com> wrote:

>
> pexpect (and other expect variants) were written specifically to avoid
> deadlocks which you are most likely seeing with Singular.  For more
> info on this, check out
>
> http://effbot.org/pyfaq/how-do-i-run-a-subprocess-with-pipes-connected-to-both-input-and-output.htm
>
> --Mike
>
>
 - Alex

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