event-loop

Should I use two asyncio event loops in one program?

丶灬走出姿态 提交于 2019-11-30 06:53:57
I want use the Python 3 asyncio module to create a server application. I use a main event loop to listen to the network, and when new data is received it will do some compute and send the result to the client. Does 'do some compute' need a new event loop? or can it use the main event loop? dano You can do the compute work in the main event loop, but the whole event loop will be blocked while that happens - no other requests can be served, and anything else you have running in the event loop will be blocked. If this isn't acceptable, you probably want to run the compute work in a separate

What is a browser event loop?

蓝咒 提交于 2019-11-30 06:29:19
I have been doing some web application programming using GWT and have been confused by the term "browser event loop". I have encountered situations where I need to execute deferred commands and "do something" after the browser event loop completes. I would like to know as to what exactly it is and what happens during the event loop process and in which order? A browser event loop is a thread started by the browser that is constantly scanning for and running different events, just like it sounds. As events occur they are put in the event queue and run in turn by the one event thread. Your

Exception “ There is no current event loop in thread 'MainThread' ” while running over new loop

老子叫甜甜 提交于 2019-11-30 04:37:29
问题 The is the simple test code and the result. import asyncio async def test(): await asyncio.sleep(1) if __name__ == '__main__': asyncio.set_event_loop(None) # Clear the main loop. loop = asyncio.new_event_loop() # Create a new loop. loop.run_until_complete(test()) # Run coroutine over the new loop Traceback (most recent call last): File "test_test.py", line 11, in <module> loop.run_until_complete(test()) File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete return

Understanding the execution order of subsequent then() handlers of an resolved promise

て烟熏妆下的殇ゞ 提交于 2019-11-30 04:37:13
问题 I am learning Promise, in order to understand it I read a bit about Event loop of JavaScript. This article briefly introduced the working of event loop such as call stack, event table and message queue. But I don't know how the call stack deal with the line containing 'return', and what happens thereafter. Below is an example that I wrote to hopefully understand how Promise works based on event loop. Also see http://jsbin.com/puqogulani/edit?js,console if you want to give it a go. var p1 =

Is it possible to create local event loops without calling QApplication::exec()?

喜欢而已 提交于 2019-11-30 04:03:42
问题 I'd like to create a library built on top of QTcpServer and QTcpSocket for use in programs that don't have event loops in their main functions (because the Qt event loop is blocking and doesn't provide enough timing resolution for the real-time operations required). I was hoping to get around this by creating local event loops within the class, but they don't seem to work unless I've called app->exec() in the main function first. Is there some way to create local event loops and allow for

Single thread concept of JavaScript running in browser

為{幸葍}努か 提交于 2019-11-30 04:02:28
The following figure is taken from Chapter 3 of the book Secrets of the JavaScript Ninja by Jon Resig. Here the author is explaining the browser event loop. The book has to say this : It’s important to note that the browser mechanism that puts the events onto the queue is external to this event loop model. The processing necessary to determine when events have occurred and to push them onto the event queue doesn’t participate in the thread that’s handling the events. So my question is it correct to say that JavaScript in browser is single threaded? I ask this question because clearly two

Single threaded and Event Loop in Node.js

大憨熊 提交于 2019-11-30 00:42:24
First of all, I am starter trying to understand what is Node.Js. I have two questions. First Question From the article of Felix, it said "there can only be one callback firing at the same time. Until that callback has finished executing, all other callbacks have to wait in line". Then, consider about the following code (copied from nodejs official website) var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8124, "127.0.0.1"); If two client requests are received simultaneously, it means the

What is an event loop in Qt?

蹲街弑〆低调 提交于 2019-11-29 22:46:09
问题 I have understood the following regarding QApplication's exec function: QApplication exec starts the main event loop. It launches the GUI. It processes the signals and calls appropriate slots on receiving them. It waits until exit is called and returns the value which was set in exit. Now, when we say event loop, does it mean that there is some while loop running in the internal code of Qt, and in that while loop the method of handling signals and slots is written? 回答1: Now, when we say event

How does Python's Twisted Reactor work?

巧了我就是萌 提交于 2019-11-29 16:31:54
问题 Recently, I've been diving into the Twisted docs. From what I gathered, the basis of Twisted's functionality is the result of it's event loop called the "Reactor". The reactor listens for certain events and dispatches them to registered callback functions that have been designed to handle these events. In the book, there is some pseudo code describing what the Reactor does but I'm having trouble understanding it, it just doesn't make any sense to me. while True: timeout = time_until_next

Grab user input asynchronously and pass to an Event loop in python

青春壹個敷衍的年華 提交于 2019-11-29 10:03:33
I am building a single player MUD, which is basically a text-based combat game. It is not networked. I don't understand how to gather user commands and pass them into my event loop asynchronously. The player needs to be able to enter commands at any time as game events are firing. So pausing the process by using raw_input won't work. I think I need to do something like select.select and use threads. In the example below, I have a mockup function of userInputListener() which is where I like to receive commands, and append them to the command Que if there is input. If have an event loop such as: