Questions tagged [event-loop]

Event loop refers to an infinite cycle of actions which is used for processing data based on callbacks and messages.

An event loop watches for I/O and timer state changes. It queues functions while waiting for unavailable resources, then dispatches them when resources are available.

References

1046 questions
16
votes
3 answers

Why can't I catch SIGINT when asyncio event loop is running?

Using Python 3.4.1 on Windows, I've found that while executing an asyncio event loop, my program can't be interrupted (i.e. by pressing Ctrl+C in the terminal). More to the point, the SIGINT signal is ignored. Conversely, I've determined that SIGINT…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
15
votes
1 answer

JavaScript Event Loop: Queue vs Message Queue vs Event Queue

Reading through a lot of JavaScript Event Loop tutorials, I see different terms to identify the queue stores messages ready to be fetched by the Event Loop when the Call Stack is empty: Queue Message Queue Event Queue I can't find the canonical…
Flavio Copes
  • 4,131
  • 4
  • 27
  • 30
15
votes
4 answers

Why is Node.js called single threaded when it maintains threads in thread pool?

Node.js maintains an event loop but then it also has by default four threads for the complicated requests. How this is single threaded when there are more threads available in the thread pool? Also, the threads assigned by the event loop for the…
rahul kumar
  • 151
  • 1
  • 5
15
votes
4 answers

Do Javascript promises block the stack

When using Javascript promises, does the event loop get blocked? My understanding is that using await & async, makes the stack stop until the operation has completed. Does it do this by blocking the stack or does it act similar to a callback and…
Stretch0
  • 8,362
  • 13
  • 71
  • 133
15
votes
3 answers

How Nodejs's internal threadpool works exactly?

I have read a lot of article about how NodeJs works. But I still can not figure out exactly how the internal threads of Nodejs proceed IO operations. In this answer https://stackoverflow.com/a/20346545/1813428 , he said there are 4 internal threads…
Nick
  • 161
  • 1
  • 8
15
votes
1 answer

Event loops and signal-slot processing when using multithreading in Qt

I've been having some problems with using QThreads which made me explore different combinations before I've found the right one. However I still don't fully understand what is really happening in the four cases shown below when it comes to event…
Moomin
  • 1,846
  • 5
  • 29
  • 47
14
votes
1 answer

Why does this line of code with 'await' trigger microtask queue processing?

The following quotes are my primary references for understanding microtask queue processing: Microtasks (which promises use) are processed when the JS stack empties. - Jake Archibald That doesn't make sense to me. One go-around of the event loop…
AnonEq
  • 267
  • 2
  • 9
14
votes
3 answers

setTimeout / Promise.resolve: Macrotask vs Microtask

I've been introduced to the concepts of Microtasks and Macrotasks for a while now, and from everything I've read, I always thought setTimeout to be considered to create a macrotask and Promise.resolve() (or process.nextTick on NodeJS) to create…
jpsfs
  • 708
  • 2
  • 7
  • 24
14
votes
1 answer

What is an event loop in Qt?

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…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
14
votes
2 answers

Recursion - Call stack fails to pop when testing the maximum stack size

Basically call stack will start to pop out the function calls one by one when the last-in function call returns. But when ever I try to create a call stack nearer to the size of its maximum, An uncaught expression is getting raised. //Code for…
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
14
votes
3 answers

What is the different between JavaScript Event loop and Node.js Event loop?

In JavaScript, the event loop is used in the engine. Here is one diagram to illustrate it from this article. (source: mybalsamiq.com) For Node.js, the event loop also implemented here. Quoting from this question. The Node.js event loop runs under…
zangw
  • 43,869
  • 19
  • 177
  • 214
14
votes
3 answers

Javascript run loop for specified time

I have a function that interfaces with a telephony program and calls people. I want to know, is there a method that I can use to call folks for a certain amount of time? I'd like to run a loop like this: while (flag = 0) { …
TheMonarch
  • 577
  • 1
  • 5
  • 19
13
votes
3 answers

Potential bug in "official" useInterval example

useInterval useInterval from this blog post by Dan Abramov (2019): function useInterval(callback, delay) { const savedCallback = useRef(); // Remember the latest callback. useEffect(() => { savedCallback.current = callback; },…
Izhaki
  • 23,372
  • 9
  • 69
  • 107
13
votes
3 answers

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

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([]()…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
13
votes
1 answer

Event loop created by asyncio.new_event_loop hangs

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…
Elektito
  • 3,863
  • 8
  • 42
  • 72
1 2
3
69 70