buffering

Why does python keep buffering stdout even when flushing and using -u?

情到浓时终转凉″ 提交于 2019-12-06 07:18:28
问题 $ cat script.py import sys for line in sys.stdin: sys.stdout.write(line) sys.stdout.flush() $ cat script.py - | python -u script.py The output is right but it only starts printing once I hit Ctrl-D whereas the following starts printing right away : $ cat script.py - | cat which led me to think that the buffering does not come from cat. I managed to get it working by doing : for line in iter(sys.stdin.readline, ""): as explained here : Streaming pipes in Python, but I don't understand why the

MFC: How to avoid flickering in child-control updates?

假如想象 提交于 2019-12-06 04:36:22
I'm been googling for days, and all I'm getting are the same answers, but is not what I want (I will describe what I do not want later). What I want is: Say I have a parent dialog that has a few CStatic child controls. The parent dialog uses black as its background when in focus, and gray when not in focus. The child static controls simply display text, but its background needs to follow the parent's background color Problem: I can get the child-controls to always track the parent's color, however the process of updating the color is slow and causes flicker. When I make the dialog to go in

stdbuf with setuid/capabilities

半腔热情 提交于 2019-12-06 01:42:28
I am reading output from another process which generates output (slow and infinite). Because I want to read this data in real-time I use "stdbuf -oL" (line-buffered, data is text). I do not have control of the generating process so I cannot modify the source to force flushing. So far stdbuf works just fine, however the process uses SOCK_RAW and needs either to be run as root, have setuid(0) or the cap_net_raw capability. When running as non-root with setuid or capabilities stdbuf seems to be ignored. Let me demonstrate the problem: This is a simple writer: #include <stdio.h> #include <unistd.h

Does ob_start affect performance of files stored on CDN?

安稳与你 提交于 2019-12-05 08:52:17
I use object buffering to buffer the output of my php pages using ob_start('ob_gzhandler'); . Does this affect the performance of the files stored in CDN? The reason for asking this question is because, one of the site indicated the following about "Output buffering is a simple way to greatly improve the performance and speed of your PHP script. Without output buffering, your script will show the HTML on the page as it’s processed – in pieces. Adding output buffering allows the PHP to store the HTML as a variable and send it to the browser in one chunk." Could you please clarify? Using ob

PHP: <<< vs ob_start

China☆狼群 提交于 2019-12-05 04:56:43
In PHP sometimes I see this: $html = <<<HTML <p>Hello world</p> HTML; Normally I would have used ob_start() : ob_start(); ?> <p>Hello world</p> <?php $html = ob_get_contents(); ob_clean(); Can you tell me what the difference between these two ways to write to the buffer and their advantages? HEREDOC ( <<< ) is just another way to write a string data into a variable. The output buffer, on the other hand, will catch all output that takes place after ob_start() including (HTML) output of any warnings or errors you might have in the code before you call ob_get_contents() ; Usually, if you just

read huge text file line by line in C++ with buffering

柔情痞子 提交于 2019-12-05 02:09:30
I need to read huge 35G file from disc line by line in C++. Currently I do it the following way: ifstream infile("myfile.txt"); string line; while (true) { if (!getline(infile, line)) break; long linepos = infile.tellg(); process(line,linepos); } But it gives me about 2MB/sec performance, though file manager copies the file with 100Mb/s speed. I guess that getline() is not doing buffering correctly. Please propose some sort of buffered line-by-line reading approach. UPD: process() is not a bottleneck, code without process() works with the same speed. You won't get anywhere close to line speed

What is a suitable buffer for Python's struct module

北战南征 提交于 2019-12-04 03:02:08
In Python I'm accessing a binary file by reading it into a string and then using struct.unpack(...) . Now I want to write to that string using struct.pack_into(...) , but I get the error "Cannot use string as modifiable buffer" . What would be a suitable buffer for use with the struct module? If you aren't trying to pack it into a specific object, just use struct.pack to return a string. Otherwise, ctypes.create_string_buffer is one way to obtain a mutable buffer. As noted in another answer, struct_pack is probably all you need and should use. However, objects of type array support the buffer

Buffering log messages in NLog and manually flushes them to target

 ̄綄美尐妖づ 提交于 2019-12-03 19:56:00
问题 I am trying to log via the NLog MailTarget. It works just fine, but i wanted to wrap the mailtarget with the BufferedTargetWrapper to buffer the log messages until a predefined codepoint, where i want to manually flush the buffer and send the previusly buffered log messages by an single mail (like defined in the mail target). If I define a FlushTimeout or the BufferSize of the BufferedTargetWrapper everything still works just fine as supposed. But if the FlushTimeout and the BufferSize is not

C# - readin from serial port buffer

匆匆过客 提交于 2019-12-03 17:54:10
I am trying to read data from an RS-232 port. Does anyone have an example of how I get the data from the port/buffer and make sure that I have all the data as it can be multiline data. Do I simply read it as follows ? string Rxstring = port.ReadLine(); Console.WriteLine(Rxstring); Try this: using System.IO.Ports; ... private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); Console.WriteLine(port.ReadExisting()); Details can be found at Coad's Code . Ron Harding Q: how to get the date from the port/buffer, or input data from your connected device. AND make sure that

How is line buffering implemented for C stdio input streams?

北战南征 提交于 2019-12-03 15:01:11
问题 I understand that fully buffered input can be implemented by issuing a single read syscall for a block of data possibly larger than required by the application. But I don't understand how line buffering could ever be applied to input without support from the kernel. I imagine one would have to read a block of data and then look for newlines, but if so, what is the difference with full buffering? To be more specific: Suppose I have an input stream FILE* in . Is there any difference between the