nonblocking

Python socket.accept nonblocking?

血红的双手。 提交于 2019-11-27 07:18:48
Is there a way I can use python's socket.accept() in a non-blocking way that simply runs it and lets me just check if it got any new connections? I really don't want to use threading. Thanks. Nathan Ostgard You probably want something like select.select() (see documentation ). You supply select() with three lists of sockets: sockets you want to monitor for readability, writability, and error states. The server socket will be readable when a new client is waiting. The select() function will block until one of the socket states has changed. You can specify an optional fourth parameter, timeout ,

Is non-blocking I/O really faster than multi-threaded blocking I/O? How?

空扰寡人 提交于 2019-11-27 05:52:57
I searched the web on some technical details about blocking I/O and non blocking I/O and I found several people stating that non-blocking I/O would be faster than blocking I/O. For example in this document . If I use blocking I/O, then of course the thread that is currently blocked can't do anything else... Because it's blocked. But as soon as a thread starts being blocked, the OS can switch to another thread and not switch back until there is something to do for the blocked thread. So as long as there is another thread on the system that needs CPU and is not blocked, there should not be any

Blocking IO vs non-blocking IO; looking for good articles [closed]

会有一股神秘感。 提交于 2019-11-27 05:04:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Once upon a time I bumped into Introduction to Indy article and can't stop thinking about blocking vs non-blocking IO ever since then. Looking for some good articles describing what are pros and cons of blocking IO and non-blocking IO and how to design your application in each case to get natural, easy to

NodeJs how to create a non-blocking computation

前提是你 提交于 2019-11-27 03:12:40
问题 I am trying to get my head around creating a non-blocking piece of heavy computation in nodejs. Take this example (stripped out of other stuff): http.createServer(function(req, res) { console.log(req.url); sleep(10000); res.end('Hello World'); }).listen(8080, function() { console.log("ready"); }); As you can imagine, if I open 2 browser windows at the same time, the first will wait 10 seconds and the other will wait 20, as expected. So, armed with the knowledge that a callback is somehow

sending a non-blocking HTTP POST request

此生再无相见时 提交于 2019-11-27 02:14:07
问题 I have a two websites in php and python. When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server. Is it possible to continue running a php/python script after sending a response to the user. In that case I'll first reply to the user and only then send the HTTP POST request to the remote server. Is it possible to create a non-blocking HTTP client in

Detect key press (non-blocking) w/o getc/gets in Ruby

陌路散爱 提交于 2019-11-27 01:51:11
问题 I have a simple task that needs to wait for something to change on the filesystem (it's essentially a compiler for prototypes). So I've a simple infinite loop with a 5 second sleep after the check for changed files. loop do # if files changed # process files # and puts result sleep 5 end Instead of the Ctrl+C salute, I'd rather be able to test and see if a key has been pressed, without blocking the loop. Essentially I just need a way to tell if there are incoming key presses, then a way to

Read timeout using either urllib2 or any other http library

安稳与你 提交于 2019-11-27 01:20:48
I have code for reading an url like this: from urllib2 import Request, urlopen req = Request(url) for key, val in headers.items(): req.add_header(key, val) res = urlopen(req, timeout = timeout) # This line blocks content = res.read() The timeout works for the urlopen() call. But then the code gets to the res.read() call where I want to read the response data and the timeout isn't applied there. So the read call may hang almost forever waiting for data from the server. The only solution I've found is to use a signal to interrupt the read() which is not suitable for me since I'm using threads.

Can SQLAlchemy be configured to be non-blocking?

℡╲_俬逩灬. 提交于 2019-11-27 00:28:42
问题 I'm under the impression that database calls through SQLAlchemy will block and aren't suitable for use in anything other than synchronous code. Am I correct (I hope I'm not!) or is there a way to configure it to be non-blocking? 回答1: You can use SQLA in a non-blocking style using gevent. Here's an example using psycopg2, using psycopg2's coroutine support: https://bitbucket.org/zzzeek/green_sqla/ I've also heard folks use the same idea with pymysql. As pymysql is in pure Python and uses the

In Win32, is there a way to test if a socket is non-blocking?

点点圈 提交于 2019-11-26 23:15:25
问题 In Win32, is there a way to test if a socket is non-blocking? Under POSIX systems, I'd do something like the following: int is_non_blocking(int sock_fd) { flags = fcntl(sock_fd, F_GETFL, 0); return flags & O_NONBLOCK; } However, Windows sockets don't support fcntl(). The non-blocking mode is set using ioctl with FIONBIO, but there doesn't appear to be a way to get the current non-blocking mode using ioctl. Is there some other call on Windows that I can use to determine if the socket is

Why is a function and a callback non-blocking in Node.JS?

梦想与她 提交于 2019-11-26 23:09:11
问题 The novice understanding of Node is that if I re-write synchronous, or in-line code, to utilize functions / callbacks, I can ensure that my code is non-blocking. I'm curious how this works in terms of the event stack. The simple example from here: Don't understand the callback - Stackoverflow is that this will block: var post = db.query("select * from posts where id = 1"); doSomethingWithPost(post) doSomethingElse(); While this wont: callback = function(post){ doSomethingWithPost(post) } db