event-loop

Why is the behavior of setTimeout(0) and setImmediate() undefined when used in the main module ?

可紊 提交于 2019-12-07 06:54:52
问题 Take the following code taken from the nodejs event loop documentation : // timeout_vs_immediate.js setTimeout(() => { console.log('timeout'); }, 0); setImmediate(() => { console.log('immediate'); }); According to the documentation : For example, if we run the following script which is not within an I/O cycle (i.e. the main module), the order in which the two timers are executed is non-deterministic, as it is bound by the performance of the process. Why is the above statement true ? Is it

Running a C++ Event Loop WITHOUT using QT

六月ゝ 毕业季﹏ 提交于 2019-12-06 15:26:02
I have been trying to develop a background Windows application in c++ to capture system wide keystrokes and mouse clicks (no I'm not writing a keystroke logger, just keystroke rates!). For this I have figured out that I need to use Windows Hooks and I came across this excellent video which gave me a basic example. Unfortunately, it uses the QT framework and for licencing (and other time based) reasons, this is not available to me currently. All I need to be able to do is adapt the code so that it does not require the "return a.exec()" line (which I believe is what starts off the event loop). A

Python event loop does not work properly with stdin

南楼画角 提交于 2019-12-06 14:29:29
I am trying to get my head around python's asyncio. I have written this piece of code just for demonstration to clear concept. import asyncio import threading async def printer(b, a): print(b) await asyncio.sleep(5) print(a) def loop_runner(loop): print('[RUNNING LOOP]') loop.run_forever() if __name__ == '__main__': event_loop = asyncio.get_event_loop() # run_forever() is blocking. running it from separate thread loop_thread = threading.Thread(target=loop_runner, args=(event_loop,)) loop_thread.start() while True: before, after = input('Before :'), input('After :') event_loop.create_task

Optimal solution to creating a “run loop” in JavaScript

那年仲夏 提交于 2019-12-06 14:26:11
问题 So it turns out the while loop blocks the event loop in JavaScript, which prevents it from being a viable solution to creating a run loop if you want your application to respond to external / async events. My question is, what techniques are used to have a "run loop" be infinite / constant but still have high performance and not block the event loop. I ran a quick test to see the performance of while , setTimeout(fn, 0) (browser), and setImmediate(fn) (node.js). var x = 1000 var isNode =

Executing slot on every application's event loop iteration

安稳与你 提交于 2019-12-06 07:01:36
问题 How can I call my slot on every iteration of application's event loop? Only way I know is to use QTimer and on every timeout (every millisecond) signal I can call my slot. But I don't like this option, it looks like workaround. Any suggestions how to do this more correctly? 回答1: From the Qt 4.7 QCoreApplication::exec() documentation: To make your application perform idle processing (i.e. executing a special function whenever there are no pending events), use a QTimer with 0 timeout. More

Freeze when using tkinter + pyhook. Two event loops and multithreading

为君一笑 提交于 2019-12-06 02:12:48
I am writing a tool in python 2.7 registering the amount of times the user pressed a keyboard or mouse button. The amount of clicks will be displayed in a small black box in the top left of the screen. The program registers clicks even when another application is the active one. It works fine except when I move the mouse over the box. The mouse then freezes for a few seconds after which the program works again. If I then move the mouse over the box a second time, the mouse freezes again, but this time the program crashes. I have tried commenting out pumpMessages() and then the program works.

How to run the Tornado event loop alongside a Kivy GUI?

烂漫一生 提交于 2019-12-05 18:59:10
My client application uses a Kivy GUI (Kivy has its own event loop) and connects to the server using the WebSocket protocol with Tornado (Tornado also has an event loop). That's why the connection part is asynchronous. I want the user to interact with the UI while a Tornado client is running an infinite asynchronous loop of listening for server messages. Here's some example code: client_test.py from tornado.ioloop import IOLoop from tornado.websocket import websocket_connect class RequestSender: url = 'server url here (no scheme)' async def _connect(self): self.conn = await websocket_connect(

Event loop created by asyncio.new_event_loop hangs

て烟熏妆下的殇ゞ 提交于 2019-12-05 08:19:26
The following code just hangs without ever printing anything: import asyncio async def foo(loop): print('foo') loop.stop() loop = asyncio.new_event_loop() asyncio.ensure_future(foo(loop)) loop.run_forever() If I use get_event_loop everything works fine. Is there something I'm doing wrong or have I stumbled upon a bug? I'm using Python 3.5.1. asyncio.AbstractEventLoopPolicy.new_event_loop documentation says: If there’s need to set this loop as the event loop for the current context, set_event_loop() must be called explicitly. import asyncio async def foo(loop): print('foo') loop.stop() loop =

Optimal solution to creating a “run loop” in JavaScript

Deadly 提交于 2019-12-04 18:47:22
So it turns out the while loop blocks the event loop in JavaScript , which prevents it from being a viable solution to creating a run loop if you want your application to respond to external / async events. My question is, what techniques are used to have a "run loop" be infinite / constant but still have high performance and not block the event loop. I ran a quick test to see the performance of while , setTimeout(fn, 0) (browser), and setImmediate(fn) (node.js). var x = 1000 var isNode = typeof window == 'undefined' function a() { var start = (new Date()).getTime() var q = 0 function next() {

How to queue lambda function into Qt's event loop?

邮差的信 提交于 2019-12-04 13:20:21
问题 Basically I need the same thing that is done like this in Java: SwingUtilities.invokeLater(()->{/* function */}); Or like this in javascript: setTimeout(()=>{/* function */}, 0); But with Qt and lambda. So some pseudocode: Qt::queuePushMagic([]() { /* function */ }); As an additional complication, I need this to work in multithreaded context. What I'm actually trying to do is to automatically run certain methods in correct thread. What the code would then look: SomeClass: