jwakely / pstreams Goto Github PK
View Code? Open in Web Editor NEWMirror of git://git.code.sf.net/p/pstreams/code
License: Boost Software License 1.0
Mirror of git://git.code.sf.net/p/pstreams/code
License: Boost Software License 1.0
I have written a python file containing some junk. I am doing this to find whether pstreams::pstderr is working properly. But only the pstreams::pstdout seems to work. These are the codes I have written.
#include <iostream>
#include "pstream.h"
using namespace redi;
main(){
ipstream proc("python testfile.py", pstreams::pstdout | pstreams::pstderr);
std::string line;
while(getline(proc.out(), line))
{
std::cout<<line<<std::endl;
}
while(getline(proc.err(), line))
{
std::cout<<line<<std::endl;
}
}
you can
write_whatever
junk you want to
If you write a valid python code in testfile.py, I am getting the expected result.
Is there any change I need to make for making the pstderr work? Thanks in advance.
See title.
The example in mainpage.html
const pstreams::pmode mode = pstreams::pstdout|pstreams::pstderr;
ipstream child("echo OUT1; sleep 1; echo ERR >&2; sleep 1; echo OUT2", mode);
char buf[1024];
std::streamsize n;
bool finished[2] = { false, false };
while (!finished[0] || !finished[1])
{
if (!finished[0])
{
while ((n = child.err().readsome(buf, sizeof(buf))) > 0)
std::cerr.write(buf, n).flush();
if (child.eof())
{
finished[0] = true;
if (!finished[1])
child.clear();
}
}
if (!finished[1])
{
while ((n = child.out().readsome(buf, sizeof(buf))) > 0)
std::cout.write(buf, n).flush();
if (child.eof())
{
finished[1] = true;
if (!finished[0])
child.clear();
}
}
}
Can anyone point me to understand how to change it to write a std::string to stdin before start looping for stdout/stderr output? Thanks.
If you run clang-tidy test_pstreams.cc
you get this complaint:
.../pstream.h:1621:7: note: Call to virtual method 'basic_pstreambuf::sync' during destruction bypasses virtual dispatch
I'm not sure what it's babbling about since sync()
isn't virtual. Is clang-tidy
stoned, or has it actually got a point here?
Hi,
I've been using pstreams library for some time, but when I upgraded the kernel to 4.19 / 5.0 (I need patches for nftables API) I started noticing problems with blocked read in glibc. I've created class on top of pstreams since I needed timeout functionality etc. After I found the problem with blocking I extended the conditions to check rdbuf()->in_avail() > 0 before I call getline, but even then it blocks. It happens mostly in async threads, which then hang till I restart whole daemon. I've tried to inspect more in depth states and I'm suspecting some buffer problems. As you can see, there is malformed string at line no.2 s=0x7f87e4000d12 " 7.526 ms.101.84 7.339 ms 1975 ", n=30)
. It should be something similar to 4 10.26.101.84 7.339 ms 7.526 ms
because it is output of traceroute command. I'm not really sure it is problem of pstreams, but I've to start somewhere and I would be grateful for any kind of advice. May be it is problem in glibc. I honestly don't know. I had my own old library to handle external processes and it has similar problems. It always stucks at some kind of read operation on buffer of external process. I've tried to upgrade distribution from Debian Stretch to Debian testing and I'm trying it with stock kernel instead of compiled one. I'm asking you first, because you have most understanding of what is going on inside pstreams and I hope you can at least help me address the issue so I can report it further. PStream.hpp is copy of pstream.h, but I removed some doxygen lines to prevent warnings. I didn't make any other modifications to it, I just prepared it in case I would have to. I'm attaching it because line numbers would probably mismatch with original. https://pastebin.com/uWYKacfr
I can recompile it with original file if needed I just can't say when it will hang. It happens randomly in range of hours and not on every testing machine I run my code on. I've asked similar question on debian glibc mailing list, but may be you can help me address the issue better.
gdb:
where
#0 __libc_read (nbytes=30, buf=0x7f87e4000d12, fd=3) at ../sysdeps/unix/sysv/linux/read.c:26
#1 __libc_read (fd=3, buf=0x7f87e4000d12, nbytes=30) at ../sysdeps/unix/sysv/linux/read.c:24
#2 0x00005594c844075d in redi::basic_pstreambuf<char, std::char_traits<char> >::read (this=0x7f87fa6c10d0, s=0x7f87e4000d12 " 7.526 ms.101.84 7.339 ms 1975 ", n=30) at /root/shaperd/projects/include/PStream.hpp:1980
#3 0x00005594c84405d1 in redi::basic_pstreambuf<char, std::char_traits<char> >::fill_buffer (this=0x7f87fa6c10d0, non_blocking=false) at /root/shaperd/projects/include/PStream.hpp:1927
#4 0x00005594c8440186 in redi::basic_pstreambuf<char, std::char_traits<char> >::underflow (this=0x7f87fa6c10d0) at /root/shaperd/projects/include/PStream.hpp:1839
#5 0x00007f87fb9bd39e in std::basic_streambuf<char, std::char_traits<char> >::sgetc (this=0x7f87fa6c10d0) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:345
#6 std::basic_streambuf<char, std::char_traits<char> >::sgetc (this=<optimized out>) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:345
#7 std::basic_streambuf<char, std::char_traits<char> >::snextc (this=<optimized out>) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:310
#8 std::getline<char, std::char_traits<char>, std::allocator<char> > (__in=..., __str=" 4 10.26.101.84 7.339 ms 7.526 ms", __delim=10 '\n') at ../../../../../src/libstdc++-v3/src/c++98/istream-string.cc:170
#9 0x00005594c84c0f83 in PStreams::Class::GetLine (this=0x7f87fa6c1090, rBuffer=..., rOutput=" 4 10.26.101.84 7.339 ms 7.526 ms") at /root/shaperd/projects/lib/libPStreams.cpp:73
my function from where it blocks
bool Class::GetLine(redi::basic_pstream<char>& rBuffer, string& rOutput)
{
const string functionName = "PStreams_Class/GetLine";
rOutput = "";
while (rdbuf()->exited() == false && rBuffer.rdbuf()->in_avail() == 0)
{
WaitFor(false, 1);
}
if (cReadDone() == false &&
rBuffer.rdbuf()->in_avail() > 0 &&
std::getline(rBuffer, rOutput).good() == true) - it blocks here - libPStreams.cpp:73
{
return true;
}
else if (cReadDone() == false &&
(rBuffer.rdbuf()->in_avail() == -1 ||
rBuffer.good() == false ||
(rBuffer.rdbuf()->in_avail() == 0 && rdbuf()->exited() == true)))
{
rBuffer.clear();
mReadDone = true;
return false;
}
return false;
}// _GetLine@PStreams_Class
Is seems 7b57b0f is 48dd2a8 missing on this mirror.
(needed for quinoacomputing/quinoa-tpl#2)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.