StackOverflow.com

VN:F [1.9.22_1171]
Rating: 8.5/10 (13 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

FastAPI BackgroundTasks vs Celery: how to reliably run work after the response is returned?

6 February 2026 @ 1:23 am

I’m building a small API with FastAPI. When a request comes in, I want to trigger a heavy/long-running task (e.g., file processing, sending emails, calling an external API, DB post-processing) without blocking the response. I started with BackgroundTasks, like this: from fastapi import FastAPI, BackgroundTasks app = FastAPI() def do_heavy_job(user_id: int): # time-consuming work (e.g., send email, process file, call external API) ... @app.post("/start") def start_job(user_id: int, background_tasks: BackgroundTasks): background_tasks.add_task(do_heavy_job, user_id) return {"status": "accepted"} But I’m worried about reliability in production (missed tasks, restarts, multiple workers, etc.). My questions: Is BackgroundTasks reliable when running behind Uvicorn/Gunicorn with multiple workers?

if statement ignoring it's condition in C?

6 February 2026 @ 12:55 am

Trying to do a complex programming exercise in C (it includes lots of auxiliary functions, and it's a bit intimidating), I ran into a problem like this: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct{ char matricula[TAM_MATRICULA]; char marca[TEXTO_CURTO]; char modelo[TEXTO_CURTO]; int anoRegisto; int tipo; int totalKms; } tipoVeiculo; void listarVeiculosMarca(tipoVeiculo vetorVeiculos[MAX_VEICULOS], int quantVeiculos) { int i; char check[TEXTO_CURTO]; printf("Insire a marca a procurar:"); lerString(check, TEXTO_CURTO); converteMaiuscula(check); if (quantVeiculos > 0) { printf("\n\n*********** LISTAGEM dos VEICULOS da MARCA: ***********\n\n"); for (i=0; i < quantVeiculos; i++) { if(procurarVeiculoMarca(vetorVeiculos, quantVeiculos, check) != -1){ escreverVeiculo(vetorVei

Does Chrome (or any other browser) upload INPUT TYPE="FILE" multiple files in parallel with HTTP 2

6 February 2026 @ 12:50 am

According to a comment in response to List is null for large files. Reproducible at will : - Yes... the actual spec: datatracker.ietf.org/doc/html/rfc7578 - when a request is using multipart/form-data it's a serialization-by-concatenation, i.e. everything arrives in-sequence. There's no interleaving, chunking, or overlapping of the data here - nor are there any concurrent requests. Now, ASP.NET Core's FormFile binder will buffer-to-memory/disk each file as it comes in, but IIRC there's no guarantee that your Controller Action will be entered-into after all uploaded files have been buffered-away. – Dai CommentedDec 12, 2025 at 7:23 But since HTTP2, opinions coalesce around "modern browsers like Chrome, Firefox, and Edge can upload multiple files using INPUT TYPE="FILE" with the multiple attribute in parallel wit

TypeORMError: Entity metadata for p#writer was not found (NextJS 16)

6 February 2026 @ 12:38 am

I am trying to use TypeORM with nextjs and postgress, everything works fine on dev server but then when I deploy to vercel or run pnpm build && pnpm dev, get errors like this below TypeORMError: Entity metadata for p#writer was not found. Check if you specified a correct entity object and if it's connected in the connection options. at ignore-listed frames EntityMetadataNotFoundError: No metadata for "p" was found. at d (.next/server/chunks/[root-of-the-server]__f4088f86._.js:1:12146) at async c (.next/server/chunks/[root-of-the-server]__f4088f86._.js:1:16462) at async p (.next/server/chunks/[root-of-the-server]__f4088f86._.js:1:17503) This is where I connect to the DB, all entities are exported in the index.ts of the entities directory import "reflect-metadata"; import { DataSource } from "typeorm"; import { Series, Story, User, Earning, Paym

Clasp login says "You are logged in as an unknown user"

6 February 2026 @ 12:20 am

When I log in using clasp login --use-project-scopes --creds creds_file.json, I get brought to the Google sign-in screen. I select my account and successfully log in. But then I get the message "You are logged in as an unknown user". When I try clasp push I get "Insufficient Permission" This was working last week. But now it doesn't work on two different computers. I'm not sure what changed. I'm an admin in the Google Workspace.

Why is callback reference not observed in useEffect

6 February 2026 @ 12:19 am

How do I render a div in a component conditionally based on a component property and the get a reference to that div when it's available? In this simplified example, the message displayed in the div varies depending on which button is pressed first. I understand why I see div.current is truthy when pressing the second button first. I don't understand why useEffect doesn't observe the change of the div loading upon the change of showHere. const Message = ({ showHere }) => { const divRef = useRef(null); useEffect(() => { if (divRef.current) { divRef.current.innerHTML = "div.current is truthy"; } }, [divRef, divRef.current]); return <>{showHere ? <div ref={divRef}>no message</div> : ""}</>; }; export default function App() { const [showInsideApp, setShowInsideApp] = useState(false); const [showInsideComponent, setSh

How to sum a total number of items sorted by different categories in Google Sheets?

6 February 2026 @ 12:12 am

Having trouble coming up with a correct formula in Google Sheets. I would like to calculate the total number of items in each category without having to manually input the specific cells to count up. For example, the total number of apples would be 13. How can I do this? Name Alice Bob Cheryl David Favorite Fruit Banana Cherry Apple Apple Number of Fruits Owned 19 33 6 7 Total Fruits Apple Banana Cherry

Using marginaleffects package to obtain marginal effects on multinomial model from nnet's multinom() function

5 February 2026 @ 11:29 pm

I have a multinomial model and am trying to estimate marginal effects for my model predictors, i.e., "how does the probability of choosing option C over A change when X increases 1 unit, or when Z is either group 1 or 2." My question is first, if there's a best way to do this using the marginaleffects package on a multinom() object, and is it perhaps just with the avg_slopes() function? I'm wondering this because the case example on the marginaleffects website doesn't use avg_slopes() which I thought would have been easiest. That makes me hesitant to trust my avg_slopes() blindly hence my question. It also uses mlogit() which I don't use so maybe that's why? I'm also a bit new to the marginaleffects package so maybe I'm probably missing something key. Another layer of confusion though is that, I saw from

Using advisory locks to coordinate database activity

5 February 2026 @ 10:06 pm

I have several different jobs that can run throughout the day to read data from various sources and update my database. I want to ensure that two jobs are not trying to update the database at once. To achieve that end, I am using Postgres session-level advisory locks. When a job starts up it creates a session and tries to acquire a session-level lock. If it cannot acquire the lock (because another job is holding that lock), it exits. That code looks roughly like this: with sessionmaker(engine)() as session: result = session.execute( select(func.pg_try_advisory_lock("SOME_KEY")) ) success = next(result)[0] if not success: sys.exit(1) # at this point we have acquired the lock # do the work In the process of testing and development, I discovered that once the lock is acquired, calling session.commit() will also release the advisory lock, which I don't want. To get a

How do I write an accessible description for a chart with data fed by a database?

5 February 2026 @ 8:43 pm

I am trying to make a website that uses lots of charts and graphs accessible. I read that each chart or graph needs to have a description that describes the data it shows. My problem is this... how? When the data comes from a database, I can't very well write a description that says something like "A line chart of revenue that shows instore sales trending up while online sales are decreasing" because I won't know if that is what it will show or not and it will obviously depend on whatever parameters were used to generate the chart. What do I really need to do to comply with accessibility standards when it comes to chart and graph descriptions?