nonblocking

Can SQLAlchemy be configured to be non-blocking?

雨燕双飞 提交于 2019-11-28 04:31:50
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? 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 sockets library, gevent patches the socket library to be asynchronous. Have a look at Tornado as they've

python Non-block read file

爷,独闯天下 提交于 2019-11-28 04:04:45
问题 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(). 回答1: O_NONBLOCK is a status flag,

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

南笙酒味 提交于 2019-11-28 03:15:29
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 understand and easy to maintain code. Would like to understand BIG picture... Goz Well blocking IO means that a given thread cannot do anything more until the IO is fully received (in the case of sockets this wait could be a long time). Non-blocking IO means an IO request is queued straight

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

為{幸葍}努か 提交于 2019-11-27 23:02:27
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 currently in non-blocking mode? A slightly longer answer would be: No, but you will usually know whether or

non-blocking “toast” like notifications for Microsoft Access (VBA)

冷暖自知 提交于 2019-11-27 22:59:19
I'm going to ASK and answer a question that I think will be useful to someone who is interested in some cool UI functions in MS Access. Answering own question Question: How to show non-blocking "toast" like notifications in Microsoft Access? that does have some sort of animation and should not block the host application!. My friend asked me about non-blocking toast like notifications for ms access. My first thought was, check google you will find plenty of samples. He wasn't happy with the samples he got. He wanted something like (JQuery) non-blocking notifications. Something that user needs

Non-Blocking read from standard I/O in C# [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-27 22:46:13
I want a non-blocking read function from console. How do I write that in C#? var buf=new byte[2048]; var inputStream=Console.OpenStandardInput(); //dispose me when you're done inputStream.BeginRead(buf,0,buf.Length,ar=>{ int amtRead=inputStream.EndRead(ar); //buf has what you need. You'll need to decode it though },null); odrm Richard Dutton has a solution on his blog : while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.F1: Console.WriteLine("You pressed F1!"); break; default: break; } } // Do something more useful } 来源:

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

痴心易碎 提交于 2019-11-27 22:22:55
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.query("select * from posts where id = 1",callback); doSomethingElse(); Ok, I understand that we should

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

会有一股神秘感。 提交于 2019-11-27 18:21:27
问题 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

How can I get non-blocking socket connect()'s?

Deadly 提交于 2019-11-27 18:13:18
问题 I have a quite simple problem here. I need to communicate with a lot of hosts simultaneously, but I do not really need any synchronization because each request is pretty self sufficient. Because of that, I chose to work with asynchronous sockets, rather than spamming threads. Now I do have a little problem: The async stuff works like a charm, but when I connect to 100 hosts, and I get 100 timeouts (timeout = 10 secs) then I wait 1000 seconds, just to find out all my connections failed. Is

Why does a read-only open of a named pipe block?

蹲街弑〆低调 提交于 2019-11-27 17:35:06
I've noticed a couple of oddities when dealing with named pipes (FIFOs) under various flavors of UNIX (Linux, FreeBSD and MacOS X) using Python. The first, and perhaps most annoying is that attempts to open an empty/idle FIFO read-only will block (unless I use os.O_NONBLOCK with the lower level os.open() call). However, if I open it for read/write then I get no blocking. Examples: f = open('./myfifo', 'r') # Blocks unless data is already in the pipe f = os.open('./myfifo', os.O_RDONLY) # ditto # Contrast to: f = open('./myfifo', 'w+') # does NOT block f = os.open('./myfifo', os.O_RDWR) # ditto