473,378 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

popen2 trouble

Hi,

I'm using the popen2 module to communicate with the crm114 text
classificator. First I used to create a subprocess, feed the text to
classify to it, close the crm's stdin file and read the results. Easy
enough.

However, the crm114 is a slow beast, and I try to increase its performanc by
using it in the "window"-mode. That means that the text fed to the
subprocess looks like this:

---START---
including bfast
---STOP---

The start/stop is detected by the crm114, and everything inbetween is
subject to classification. This simple protocol allows multiple
classifications without terminating the crm114 subprocess in between.

When performing this in my console window, everything works as expected. I
can paste several blocks of text that look like the above one, and the
crm114 constantly outputs classification results.

But when I try it from python like this
out, inn, err = _.get_crminstance(path, _.classify_program)

t = '%s\n%s\n%s\n' % (_.START, text, _.STOP)
logger.debug(t)
inn.write(t)
inn.flush()
#inn.close()

res = out.read().strip()
e = err.read().strip()

my program hangs. Uncommenting the inn.close() helps somewhat as then the
out.read() returns, but only after a minute or so. And I don't want to
close it anyway, because I want to use it for the next classification.

Any suggestions? I know that there are subtle differences between files and
tenminals, but I'm no unix expert, so I'm somewtaht lost.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #1
2 1418
Hello Diez,

"Diez B. Roggisch" wrote:
When performing this in my console window, everything works as expected. I
can paste several blocks of text that look like the above one, and the
crm114 constantly outputs classification results.


Try using the 'bufsize' optional argument in the call to popen2. Set it
to 0 to disable all buffering, if you are writing in large chunks (e.g.
calling inn.write(bigstring)).
Armin
Jul 18 '05 #2
> Try using the 'bufsize' optional argument in the call to popen2. Set it
to 0 to disable all buffering, if you are writing in large chunks (e.g.
calling inn.write(bigstring)).


That didn't work - now I'm using pexpect, which simulates a tty.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guy | last post by:
Hi I was given an exstremly useful answer to a problem that I had in windows. I'm relativly new with python, but find it exstremly useful. I'm creating a script to run test files and record...
1
by: | last post by:
This could possibly be a bug, but I don't understand it fully so I'm posting here first. Searching the list told me other people are having this problem too. I have created a class which...
1
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): ---------------------...
4
by: Rembrandt Q Einstein | last post by:
I am running an external command and I need to know a) when it is done and b) what it wrote to both stdout and stderr. After a little searching, I found the popen2 module and used the Popen3...
1
by: Magnus Lycka | last post by:
I'm trying to read standard out in a process started with popen2 in a non-blocking way. (Other good ways of doing this than the one I tried are appreciated.) I've tried to dumb down my code to...
9
by: Martin P. Hellwig | last post by:
Hi all, I was doing some popen2 tests so that I'm more comfortable using it. I wrote a little python script to help me test that (testia.py): --------------------------------- someline =...
3
by: mikem76 | last post by:
How do I automatically redirect stdout and stderr when using os.popen2 to start a long running process. If the process prints a lot of stuff to stdout it will eventually stop because it runs out...
3
by: Daniel Klein | last post by:
Here's a c routine that prints a single line : #include <stdio.h> main() { printf ("Hello World!\n"); } And now the Python program (called 'po.py') that uses 'popen2' :
1
by: diego | last post by:
I'm trying to understand how popen2 works. Found in this group, that popen2.popen2 can cause trouble so i chose win32pipe.popen2. have a look a the listing of 2 files: ekmain.py: **************...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.