nonblocking

python Non-block read file

拟墨画扇 提交于 2019-11-29 10:57:25
I want to read a file with non-block mode. So i did like below import fcntl import os fd = open("./filename", "r") flag = fcntl.fcntl(fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(fd, fcntl.F_SETFD, flag | os.O_NONBLOCK) flag = fcntl.fcntl(fd, fcntl.F_GETFD) if flag & os.O_NONBLOCK: print "O_NONBLOCK!!" But the value flag still represents 0. Why..? i think i should be changed according to os.O_NONBLOCK And of course, if i call fd.read(), it is blocked at read(). O_NONBLOCK is a status flag, not a descriptor flag. Therefore use F_SETFL to set File status flags , not F_SETFD , which is for setting

SSH module for python

喜欢而已 提交于 2019-11-29 10:03:36
问题 I have to do a job (using my web server) on a remote machine that takes about 10 minutes. I have used pxssh module in python for the same but it gives me "timeout error"(non blocking). Now, I am using paramiko but that comes back as soon as it gives the instruction. I want the web server to wait till the job is complete. Is there any python SSH module available for this. Or Can we achieve the same by changing any configuration settings of pxssh or paramiko ? 回答1: You can use the recv_exit

Is the UNLINK command always better than DEL command?

喜夏-厌秋 提交于 2019-11-29 10:00:20
In Redis 4.0, there is a new command UNLINK to delete the keys in Redis memory. This command is very similar to DEL: it removes the specified keys. Just like DEL a key is ignored if it does not exist. However the command performs the actual memory reclaiming in a different thread , so it is not blocking, while DEL is . This is where the command name comes from: the command just unlinks the keys from the keyspace. The actual removal will happen later asynchronously. So one can always (100% times) use UNLINK instead of DEL as UNLINK is nonblocking, unlike DEL, right? Before discussing which one

Non-Blocking method for parsing (streaming) XML in python

*爱你&永不变心* 提交于 2019-11-29 04:23:56
I have an XML document coming in over a socket that I need to parse and react to on the fly (ie parsing a partial tree). What I'd like is a non blocking method of doing so, so that I can do other things while waiting for more data to come in (without threading). Something like iterparse would be ideal if it finished iterating when the read buffer was empty, eg: context = iterparse(imaginary_socket_file_wrapper) while 1: for event, elem in context: process_elem(elem) # iteration of context finishes when socket has no more data do_other_stuff() time.sleep(0.1) I guess SAX would also be an option

python: nonblocking subprocess, check stdout

风流意气都作罢 提交于 2019-11-29 02:34:50
Ok so the problem I'm trying to solve is this: I need to run a program with some flags set, check on its progress and report back to a server. So I need my script to avoid blocking while the program executes, but I also need to be able to read the output. Unfortunately, I don't think any of the methods available from Popen will read the output without blocking. I tried the following, which is a bit hack-y (are we allowed to read and write to the same file from two different objects?) import time import subprocess from subprocess import * with open("stdout.txt", "wb") as outf: with open("stderr

What is the preferred way of performing non blocking I/O in Ruby?

一世执手 提交于 2019-11-29 02:13:55
If say I want to retrieve a web page for parsing, but not block the CPU while the I/O is taking place. Is there something equivalent to Python's Eventlet library? Theo The best HTTP client library for Ruby is Typhoeus , it can be used to perform multiple HTTP requests in parallel in a non-blocking fashion. There is a blocking and non-blocking interface: # blocking response = Typhoeus::Request.get("http://stackoverflow.com/") puts response.body # non-blocking request1 = Typhoeus::Request.new("http://stackoverflow.com/") request1.on_complete do |response| puts response.body end request2 =

Confused about OpenSSL non-blocking I/O

狂风中的少年 提交于 2019-11-29 01:37:18
问题 In general, the OpenSSL library (C API) seems to offer two ways to do everything: you can either use plain system sockets configured to your liking, or you can use OpenSSL BIO objects which are sort of like streams. However, I'm often confused by some of the duplicated functionality. For example, how do you make an SSL connection non-blocking? One way seems to be to simply access the underlying file descriptor and set it to non-blocking using fcntl . But there is also an OpenSSL API function

Is there a Push-based/Non-blocking XML Parser for Java?

﹥>﹥吖頭↗ 提交于 2019-11-28 22:07:52
问题 I'm looking for an XML parser that instead of parsing from an InputStream or InputSource will instead allow blocks of text to be pushed into the parser. E.g. I would like to have something like the following: public class DataReceiver { private SAXParser parser = //... private DefaultHandler handler = //... /** * Called each time some data is received. */ public void onDataReceived(byte[] data) { parser.push(data, handler); } } The reason is that I would like something that will play nice

When a non-blocking send() only transfers partial data, can we assume it would return EWOULDBLOCK the next call?

≡放荡痞女 提交于 2019-11-28 21:05:42
问题 Two cases are well-documented in the man pages for non-blocking sockets: If send() returns the same length as the transfer buffer, the entire transfer finished successfully, and the socket may or may not be in a state of returning EAGAIN/EWOULDBLOCK the next call with >0 bytes to transfer. If send() returns -1 and errno is EAGAIN/EWOULDBLOCK, none of the transfer finished, and the program needs to wait until the socket is ready for more data (EPOLLOUT in the epoll case). What's not documented

Golang blocking and non blocking

夙愿已清 提交于 2019-11-28 19:43:32
问题 I am somewhat confused over how Go handles non blocking IO. API's mostly look synchronous to me, and when watching presentations on Go, its not uncommon to hear comments like "and the call blocks" Is Go using blocking IO when reading from files or network? Or is there some kind of magic that re-writes the code when used from inside a Go Routine? Coming from a C# background, this feels very non intuitive, in C# we have the await keyword when consuming async API's. Which clearly communicates