buffering

jQuery AJAX load and Youtube API iframe

前提是你 提交于 2020-01-05 10:08:08
问题 i'm working on a webpage. I'm using jQuery load (AJAX) function to dynamically load new content into the content div. In each of these content divs there is an image. When you click on that image a Youtube embedded video (iframe) should start playing. Everything works so far, but there is one thing, which is kind of strange: Whenever i start playing a Youtube Video the buffering starts. If i now want to load a new content into the content div while buffering the jQuery load function gets

What is a suitable buffer for Python's struct module

北城余情 提交于 2020-01-01 08:53:15
问题 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? 回答1: 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. 回答2: As noted in

C# - readin from serial port buffer

岁酱吖の 提交于 2020-01-01 06:34:09
问题 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); 回答1: 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. 回答2: Q:

std::ifstream buffer caching

≡放荡痞女 提交于 2019-12-30 17:32:16
问题 In my application I'm trying to merge sorted files (keeping them sorted of course), so I have to iterate through each element in both files to write the minimal to the third one. This works pretty much slow on big files, as far as I don't see any other choice (the iteration has to be done) I'm trying to optimize file loading. I can use some amount of RAM, which I can use for buffering. I mean instead of reading 4 bytes from both files every time I can read once something like 100Mb and work

Problems with sys.stdout.write() with time.sleep() in a function

岁酱吖の 提交于 2019-12-30 09:37:16
问题 What I wanted is printing out 5 dots that a dot printed per a second using time.sleep(), but the result was 5 dots were printed at once after 5 seconds delay. Tried both print and sys.stdout.write, same result. Thanks for any advices. import time import sys def wait_for(n): """Wait for {n} seconds. {n} should be an integer greater than 0.""" if not isinstance(n, int): print 'n in wait_for(n) should be an integer.' return elif n < 1: print 'n in wait_for(n) should be greater than 0.' return

Why a script that uses threads prints extra lines occasionally?

ⅰ亾dé卋堺 提交于 2019-12-28 16:03:30
问题 If print s is replaced by print >>sys.stderr, s then the effect vanishes. import random, sys, time import threading lock = threading.Lock() def echo(s): time.sleep(1e-3*random.random()) # instead of threading.Timer() with lock: print s for c in 'abc': threading.Thread(target=echo, args=(c,)).start() Example # Run until empty line is found: $ while ! python example.py 2>&1|tee out|grep '^$';do echo -n .;done;cat out Output .................... b c a The output should not contain empty lines,

fprintf function not working but it returns positive number

浪尽此生 提交于 2019-12-25 05:07:26
问题 I'm using fprintf in the following way. Everything seems to be ok but fprintf doesn't print to my file at all! fprintf(pFile, "%s\n", "print"); Something that is strange is that fprintf returns OK . it returns 6 in the above code, but not printing to file! The file is created successfully but is empty. changing it to printf is printing and OK too. 回答1: fprintf and the other stdio output functions are buffered, which means that the output is first stored in memory, and not actually printed

How to disable line buffering of input in xterm from program?

谁说我不能喝 提交于 2019-12-25 03:12:16
问题 Ie, how to get keystrokes send directly to my program without waiting for the user to press enter. Basicly I'm trying get something like curses's cbreak() call. (But I can't use curses due a couple of bugs/misfeatures that I haven't been able to work around.) This seems like something that should just be a trival escape sequence, but I haven't been able find anything. 回答1: Lookup termios and the tcsetattr function. 回答2: Isn't this called the "raw mode"? If so, this might help you. 来源: https:/

Python Recv() stalling

我只是一个虾纸丫 提交于 2019-12-25 02:03:45
问题 I'm writing a very basic HTTP client: import socket from socket import * Payload = """GET /test.html HTTP/1.1 Accept: */* Accept-Language: en-us User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0) Accept-Encoding: gzip, deflate Proxy-Connection: Keep-Alive Host: example.com Pragma: no-cache """ def SendAndReceive(Host, Payload): s = socket(AF_INET, SOCK_STREAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.connect(Host) s.sendall(Payload) tdata=[] while True: data = s

Writing data into file: fflush() takes a lot of time

你离开我真会死。 提交于 2019-12-23 18:40:18
问题 I have a requirement wherein I have to buffer a lot of data (in GBs), for future use. Since there isn't enough RAM available for buffering such huge amount of data, I decided to go for storing the data in a file. Now the pitfall here is that while I am writing the data to the file, other threads might need that "buffered" data and so I have to flush the file stream every time I write something to it. Precisely, the data is video frames that I buffer as pre-recorded data (like a TiVo) and