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
8
votes
1 answer

Why is there a distinction between microtask and (macro)task in JavaScript?

Conceptually just having one queue for jobs seems to be sufficient for most use-cases. What are the reasons for having multiple queues and distinguishing those into "microtasks" and (macro)"tasks"?
james
  • 93
  • 5
8
votes
1 answer

How does the following queueMicrotask polyfill fallback to using setTimeout?

Consider the following polyfill for queueMicrotask. if (typeof window.queueMicrotask !== "function") { window.queueMicrotask = function (callback) { Promise.resolve() .then(callback) .catch(e => setTimeout(() => { throw e; })); …
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
8
votes
2 answers

How can we block event loop?

I have studied about the event loop in Node.Js, it work in asynchronous and non-blocking manner to process the request. Is there any way so that we can block the execution of event loop?
Digvijay Rathore
  • 637
  • 1
  • 6
  • 21
8
votes
4 answers

Is there a faster way to yield to Javascript event loop than setTimeout(0)?

I am trying to write a web worker that performs an interruptible computation. The only way to do that (other than Worker.terminate()) that I know is to periodically yield to the message loop so it can check if there are any new messages. For example…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
8
votes
1 answer

How to reset an asyncio eventloop by a worker?

I'm working with an asyncio forever() eventloop. Now I want to restart the loop (stop the loop and recreate a new loop) after a process or a signal or a change in a file, but I have some problems to do that: Here are three simplified code snippets…
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
8
votes
2 answers

asyncio event_loop in a Flask app

What is the best method to have an asyncio event loop run in a Flask app? My main.py looks like this: if __name__ == '__main__': try: app.run(host='0.0.0.0', port=8000, debug=True) except: logging.critical('server: CRASHED:…
Mugen
  • 8,301
  • 10
  • 62
  • 140
8
votes
1 answer

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

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…
SangminKim
  • 8,358
  • 14
  • 69
  • 125
8
votes
1 answer

What is event_loop_policy and why is it needed in python asyncio?

The event loops documentation mentions event_loop_policy but doesn’t describe what it is and why this abstract layer is needed in detail. (the documentation even says one can customize this layer). In addition, help(asyncio.get_event_loop_policy())…
SangminKim
  • 8,358
  • 14
  • 69
  • 125
8
votes
1 answer

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

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…
ng.newbie
  • 2,807
  • 3
  • 23
  • 57
8
votes
1 answer

What can cause the simple invocation of asyncio.new_event_loop() to hang?

I am using the following function to force a coroutine to run synchronously: import asyncio import inspect import types from asyncio import BaseEventLoop from concurrent import futures def await_sync(coro: types.CoroutineType, timeout_s:…
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
8
votes
1 answer

When does the browser's event loop start?

I'm using a framework which features auto-connecting to server on page load. I can disable it by passing options arguments, but the line that confuses me is this: You can prevent this initial socket from connecting automatically by disabling…
Howie
  • 2,760
  • 6
  • 32
  • 60
8
votes
2 answers

How can I detect a hang in QEventLoop?

I am not sure if the title of my question is formulated correctly, so to explain what I really mean, consider the following example: I create a QApplication and a QWidget with a QPushButton on it. Then I attach a handler to the click signal from the…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
7
votes
2 answers

Possible to run multiple main loops?

I'm working with both libfuse and the glib event interface and I've run into an issue where I need to run multiple main loops concurrently (glib's g_main_loop_run and fuse_loop_mt). I've already attempted to created a detached thread for glib's…
ben lemasurier
  • 2,582
  • 4
  • 22
  • 37
7
votes
2 answers

Thoughts on a different way to running a win32 event loop without WndProc?

Whilst messing around with multithreading, callbacks, win32 api functions, and other troublesome troubles, I received an idea event. (hehehe) What if, instead of defining a global (or static when designing a class) callback function, I instead…
acpluspluscoder
  • 446
  • 1
  • 4
  • 10
7
votes
1 answer

How does really work rendering in browser (event loop)

I've created simple demos, let's get started... Should to say what we have to use chrome and firefox for comparison Demo 1: block.addEventListener("click", () => { block.style.transform = "translateX(500px)"; block.style.transition = ""; …
MaximPro
  • 563
  • 8
  • 21