1,143 questions
Advice
1
vote
2
replies
65
views
An inquiry regarding Promises vs Callbacks and performance impact within the event loop
so I have been diving into NodeJS's internals and specifically in the event loop and how it handles different phases and whilst I was reading and wrapping my head around things I had a thought about ...
2
votes
1
answer
100
views
What are the advantages/disadvantages of starting a new `ThreadPoolExecutor` when doing `loop.run_in_executor`?
Looking at the documentation for Event Loop, there is this example:
import asyncio
import concurrent.futures
def blocking_io():
# File operations (such as logging) can block the
# event loop: ...
1
vote
1
answer
94
views
Py-cord RuntimeError: There is no current event loop in thread 'MainThread'
I've returned to a bot I created using the py-cord module several months ago, on a new device where I've reinstalled py-cord. The bot loaded fine when I was originally working on it, but now when I ...
0
votes
0
answers
44
views
FastAPI + Azure functions (The event loop is already running)
I'm using FastAPI inside an Azure Function app with a simple synchronous endpoint doing a query_entities on a TableClient object (the endpoint response is fast).
Everything is working but when ...
0
votes
1
answer
107
views
Why does my websocket connection get blocked?
I have a simple FastAPI server with just one WebSocket endpoint. It receives a terminal command, executes it locally, and broadcasts the stdout to the client every second:
from fastapi import FastAPI, ...
2
votes
1
answer
163
views
Long running asyncio tasks freeze after ~1 hour. How can I debug?
I have a long running Python application built on asyncio. It launches several background tasks that run indefinitely and occasionally performs CPU work using asyncio.to_thread. Everything works fine ...
2
votes
1
answer
177
views
Why does setTimeout execute before fetch .then despite microtask priority? [duplicate]
I'm running the code below. The output I was expecting was:
Start -> End -> While expires -> joke -> setTimeout
However, the output I’m actually getting is:
Start -> End -> While ...
0
votes
1
answer
69
views
What happens if setTimeout and fs.readFile callbacks are ready at the same time in Node.js?
I'm trying to deeply understand how the Node.js event loop works, especially when its says it sits idle before poll phase.
const fs = require("fs");
setTimeout(() => {
console.log(&...
1
vote
0
answers
109
views
Event Loop behaves differently with blocking code
This is not a duplicate of another question, as I've searched here and did not find an answer.
I'm learning about the Node.js event loop and tried the following code, which behaves differently ...
2
votes
3
answers
439
views
How do I create thread-safe asyncio background tasks?
I have an event loop running in a separate thread from the main thread, and I would like to add a background task to this event loop from the main thread using the asyncio.create_task function.
I am ...
0
votes
1
answer
84
views
FuncAnimation blocks the main thread after finishes
I am using FuncAnimation in a Jupyter notebook. Here is the code (in Jupytext's "percent" format, where every # %% indicates a new cell):
# ---
# jupyter:
# jupytext:
# formats: ipynb,...
-1
votes
1
answer
259
views
nodejs event loop lag 300ms and huge request latency [closed]
I have a next.js website that under the load 80 requests per seconds (for one pod) shows huge latency 20-30 seconds to handle a simple request like API call.
I checked event loop lag and under the ...
1
vote
0
answers
170
views
FastAPI Async Setup [duplicate]
I'm working on a FastAPI application where I need to initialize an async service by loading some large backing data files asynchronously. However, I'm running into issues when using fastapi dev (...
0
votes
1
answer
60
views
Quarkus: How to run long-ish IO tasks during the SSL-handshake without blocking the event loop?
We have a non-negotiable (compliance) requirement to verify a client certificate against a third-party REST service during SSL handshake for our Quarkus-based webservice. We implemented this using a ...
2
votes
1
answer
128
views
Why does "finally" delays the execution of "then" attached to it?
In this example:
const foo = async () => {
const a = await (Promise.resolve(1).then(v => console.log(v)));
console.log('foo');
return 1;
}
const value = foo();
value
.then(a => ...
0
votes
3
answers
108
views
Different order for timers when spliting in 2 calls or in a single
In the below code I run 2 sets of tests where a timer is either split in 2 nested calls to setTimeout() and a single call with the timeout set to the sum of both previous calls.
However, I notice that ...
1
vote
1
answer
142
views
What is the order of microtasks in multiple Promise chains?
Out of an academic interest I am trying to understand the order of microtasks in case of multiple Promise chains.
I. Two Promise chains
These execute in a predictable "zipped" way:
Promise....
0
votes
1
answer
39
views
Why does NodeJs run twice uv_run()?
Why does NodeJs call the Event Loop method uv_run() twice when I executed the command:
node file.js
// file.js
setTimeout(() => {
console.log('1');
}, 0);
output
1
0
votes
1
answer
105
views
When does Promise resolve/reject actually add a micro task?
When does Promise resolve/reject actually add a micro task?
I read the Promise/A+ implementation code from here, and understood that task adding action is triggered after resolve() (the mentioned ...
1
vote
2
answers
119
views
What queues actually exist in the event loop
Most sources say that there are two queues in the Event Loop: microtask queue and macrotask queue. But also some sources highlight the third queue (callbacks generated by requestAnimationFrame) and ...
1
vote
2
answers
157
views
Sequence of promise.race() in the event loop
This code, below, executes as a result:
script start
promise1
promise2
script end
promise3
race: A
Chrome version 131.0.6778.26, and node environment 22.4 both give the same result
Why is it that “‘...
1
vote
1
answer
109
views
Why is the worker's onmessage executing after a macro task?
Event loop execution order
I'm studying how the Javascript event loop works for a future presentation, but I've come across an unexpected behavior with the information I have so far. Simply put, when ...
0
votes
0
answers
107
views
Event loop in Node JS for Promises
I was going through the event loop in JavaScript and how it makes the JS to perform asynchronous operations even though it is a single threaded language. In that I learnt that the microtasks or ...
3
votes
2
answers
185
views
JavaScript event loop does NOT "run to completion"
According to MDN, messages in the JavaScript event loop "run to completion".
(https://developer.mozilla.org/docs/Web/JavaScript/Event_loop#run-to-completion)
But I have created a case where ...
-5
votes
2
answers
86
views
How is the promise settled by the time it is logged?
I have the following code:
async function get_exam_score() {
const exam_score = Math.random() * 10;
if (exam_score < 5) {
throw("You failed");
}
}
const promise = ...
1
vote
0
answers
33
views
Why puppeteer blocks callbacks from execution?
This code as it is opens the browser and read a txt file line by line:
line 1
line 2
line 3
Stream closed
The thing I don't understand is why placing const browser = await puppeteer....
1
vote
2
answers
66
views
Why does this Node.js script produce different output each time? [duplicate]
This script is from a Nodejs introducing book. This part is about the event loop of Javascript.
const sleep_st = (t) => new Promise((r) => setTimeout(r, t));
const sleep_im = () => new ...
1
vote
2
answers
93
views
How does the event loop handle timing in a single-core CPU with multiple processes
There are many ways I can think of asking this question. Let's say we have a single-core CPU on which the OS is running two processes. Process 1 is a Node application and process 2, we don't care ...
0
votes
1
answer
155
views
ERROR: Event loop is closed in ThreadPoolExecutor
In a .py module I created this function
from utils.telegram_utils import telegram_message
...
counter = count(1)
def open_websites_with_progress(url):
risultato = ...
1
vote
0
answers
45
views
Can Flutter support "capture" and "bubble" phases for keyboard events like in JavaScript?
In GUI development, there are typically two different behaviors for handling global shortcut keys:
High-priority global shortcuts: These shortcuts take precedence over all other input. If a global ...
0
votes
3
answers
167
views
Why setTimeout is executing this way
Code:
setTimeout(() => console.log("1"), 1000)
const startTime = Date.now()
while (Date.now() - startTime < 5000);
setTimeout(() => console.log("2"), 0)
setTimeout(() => console.log("...
3
votes
2
answers
94
views
Behaviour of setInterval with respect to Event loop
Trying to figure out why the output of the following code is the way it is
console.log("Start");
setInterval(function() {
console.log("setInterval");
}, 5000);
let date = new Date();
while(...
1
vote
1
answer
229
views
Python Asyncio source code analysis: Why does `_get_running_loop` in Python execute the C implementation instead of the Python one?
I've been exploring the async source code and noticed that the function _get_running_loop() is defined both in Python and has a note stating it's implemented in C (in _asynciomodule.c).
# python3.11/...
1
vote
0
answers
155
views
How to fork Qt6 program
I have already exhaustively googled this topic, and the answer is "don't do it".
However I am kind of stuck between a rock and a hard place, so I need to thoroughly explore this topic before ...
-1
votes
1
answer
167
views
Event loop is closed- pytest- FastAPI
In my fastapi application i have written test cases using pytest.
My tests folder includes
conftest.py
import pytest
from fastapi.testclient import TestClient
from main import app
@pytest.fixture(...
0
votes
1
answer
405
views
Priority of react's useEffect in Event-Loop
Background
react 18.3
chrome browser v127
Question
import { useEffect, useState } from 'react'
function App() {
const [state, setState] = useState(0);
console.log(1);
queueMicrotask(() => {...
-4
votes
1
answer
127
views
Node/ExpressJs fail to handle 1000 requests at the same time
I have 2 expressjs servers:
Server A:
const express = require('express')
const axios = require('axios');
const app = express()
const port = 3000
function deepSleep (duration) {
const start = new ...
0
votes
0
answers
49
views
useEffect and promise priority in inital and subsequent renders
I have below code and help me to find the output with accurate explanation.
'infiniteLoopProtection:false'
import * as React from "react";
import { useState, useEffect } from "react&...
4
votes
1
answer
515
views
Event loop delay
I have this simple code in NodeJs
const { eventLoopUtilization } = require('perf_hooks').performance;
const { monitorEventLoopDelay } = require('perf_hooks');
const h = monitorEventLoopDelay({ ...
1
vote
1
answer
351
views
When using AsyncClients in Google Cloud Python SDK, got future attached to a different loop
I'm quite new to using asyncio in Python. Originally I have a sync function speak:
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
def speak(*args):
# omitted
...
0
votes
1
answer
219
views
Integrating sdbus-cpp with the GLib event loop
I need to integrate some code written using sdbus-cpp with my application's event loop, which is the GLib's GMainLoop.
sdbus-cpp's IConnection interface declares the getEventLoopPollData() function ...
0
votes
1
answer
106
views
Vertx single thread become slower when client call many concurrently of APIs to vertx service
I expect your ideas so much for my situation.
I built a RestfulAPI using vertx 4.5.7, vertx-pg-client same version.
When starting I configured pool like this:
final PgConnectOptions connectOptions = ...
0
votes
1
answer
63
views
callback queue , call stack and registered event like setTimeout
what happens if any event is register (like setTimeout) but it takes more time (assume 5,6 min ), and currently call stack and callback queue is completed all task and it is empty, so the program is ...
0
votes
1
answer
41
views
How to make Firebase Cloud Function wait for a stream to close before terminating
I store an object to Cloud Storage like this:
const bucket = getStorage().bucket();
const fileRef = bucket.file("/foo/bar");
const storageWriteStream = fileRef.createWriteStream();
const ...
0
votes
1
answer
504
views
How to properly close a WebSocket connection after running an asynchronous function in Python?
I am running into this problem where the websocket will not close after I run an asynchronous function that asks for input ( i think its interrupting the main event loop or something).This code is ...
0
votes
0
answers
50
views
Why aren't nested `setImmediate` callbacks executed on the same tick of event loop?
According to the node.js docs about event loop:
Each phase has a FIFO queue of callbacks to execute. While each phase is special in its own way, generally, when the event loop enters a given phase, ...
0
votes
1
answer
137
views
Add index to AsyncIOMotorClient while having Async tests
I have a mongo class for my fastAPI application:
`
from motor.motor_asyncio import AsyncIOMotorClient
from config import settings
import asyncio
class Mongo:
def __init__(self):
client = ...
-4
votes
2
answers
200
views
Async operation like fetch, async/await are executed after syncronous code is executed then why microtask queue is given more priority?
micro task Queue consist of callbacks/resolved functions from fetch, async/await. but why its given more priority then callback queue because sync code is executed first and then afterward async ...
0
votes
2
answers
119
views
requestAnimationFrame and its lifecycle
I realized that I was confused with requestAnimationFrame, although some time ago I thought I understood how it works.
So what is the essence of my problem:
They say that requestAnimationFrame, namely ...
0
votes
1
answer
221
views
Async/await promises alternative. Rewrite await to Promise
I was trying to understand how await works in different scenarious, and camse across a problem.
new Promise(async (resolve, reject) => {
resolve();
console.log(await Promise.resolve(7))
...