It's sometimes annoying to see people use lazy solutions and refuse to learn the proper way, but since I took ownership of the important modules I use early on, I've built a small bubble of good software I can build upon.
465 karma · joined August 25, 2021
It's sometimes annoying to see people use lazy solutions and refuse to learn the proper way, but since I took ownership of the important modules I use early on, I've built a small bubble of good software I can build upon.
Containers are fine for a server after installing the runtime, which is already one too many steps. There isn't a self-contained app format that can run without installing something else before starting it.
Unrelated question: does "Cal" mean Berkeley here? Do you really need to "supplement it with self-teaching"? I don't really understand why state schools are viewed that way, since Berkeley consistently ranks world top-10.
More precisely: making a freely elected government more vulnerable to violence won't yield an improvement.
After Congress was attacked to try to overturn an election, I think "battle" isn't the wrong word.
> Last week he makes a very divisive speech
It divides people who want to overturn elections from those who don't, I guess. That doesn't seem like a bad thing.
Call it whataboutism, but his predecessor's speeches were much more divisive, and for worse reasons.
Here's a quote from him before the capitol attack [1]:
> “Republicans are constantly fighting like a boxer with his hands tied behind his back. It’s like a boxer. And we want to be so nice. We want to be so respectful of everybody, including bad people. And we’re going to have to fight much harder. …
> “We’re going to walk down to the Capitol, and we’re going to cheer on our brave senators and congressmen and women, and we’re probably not going to be cheering so much for some of them, because you’ll never take back our country with weakness. You have to show strength, and you have to be strong.”
To summarise: Fight, but don't be violent. Go to the capitol, cheer, but actually don't, and definitely don't be weak. We're getting hit and we're so nice [nothing else said, but that's definitely implied to be a bad thing].
I wouldn't do it differently if I wanted to incite violence while keeping a way of pretending I didn't in court.
[1] https://www.nytimes.com/2021/01/10/us/trump-speech-riot.html
Giving more weight to people willing to threaten violence won't fix your problems.
Where do you get "paramilitary" from? This is the Justice Department, not the FBI. All the article says is:
> the new unit will be part of the National Security Division and will work to "ensure that these cases are properly handled and effectively coordinated" across the department and around the country.
That seems to imply a bureaucratic effort, nothing like what you're claiming.
> those people actually got inside and just milled around. there was no plot, no mission.
Some photos suggest otherwise [1].
> isnt it established fact the fbi had agents actively provoking the mob? known persons on video involved, not being prosecuted?
No. Care to provide sources?
[1] https://www.theguardian.com/us-news/2021/jan/10/us-capitol-m...
But a thread has a separate call stack. Returning and calling another function in the same stack just involves moving the stack pointer by a few bytes. Switching to another thread’s stack will invalidate much more cache, while running an async task until await will make the best use of the existing cache, and switch (much closer in RAM than in another thread) only when it makes sense, i.e. the previous task started waiting on something.
> It only matters if you are at capacity because otherwise the active requests will be cached.
CPU cache is a few megabytes. That definitely won’t hold hundreds of requests if they all transfer substantial data, even if you can handle thousands or more.
- the master key derives from 1. your password, and 2. a long, random key that you type manually on each new device (so you can’t brute-force the password just from the server’s data, and you can’t decrypt the data just from your hard drive without the master password),
- none of these keys ever leave your devices (encryption and decryption happen client-side),
- the key is deleted from RAM, locking the vault, if you’re inactive for too long.
That makes some attacks hard. It will be defeated if malware can get 1. your secret key and 2. your master password. But in that case, your login cookies and what you type in login forms are vulnerable too, so there isn’t much difference.
They also store regular copies of your vault in a backup folder. If Satan buys them and they try to lock you out, just decrypt your backups and move somewhere else.
For async tasks, it means return, then call. For threads, it means moving to an entirely different stack, somewhere else in memory. “Loading context” is more expensive in the latter case.
> Maybe using a stack means using more cache lines than coroutines, but you'd have to be right at the edge of capacity for active requests for it to matter.
Why? Cache doesn’t only speed things up when capacity is full. Anything we have to reload from RAM will take time to load.
If you use pure Python for long tasks, you're right that a ProcessPoolExecutor would be better.
Because that's the correct way. print("hello, world!") will block for a very short time, so it's not worth sending to a thread pool.
> In fact most, if not all, of the examples in the tutorial use "async def."
That's again because they show the correct way to use async.
Using async correctly, when it applies is preferable to a synchronous function. The docs encourage you to do it if you know how, and if your use case fits an async function.
> So I don't think it's surprising if developers new to FastAPI tend to use async by default.
It is to me, because the docs are clear:
- if you know your function can be made async properly, make it so,
- if your function blocks, use "def",
- if you don't know enough to choose, use "def".
People who complain that the event loop blocks too often simply haven't read the docs well enough.
Threads have separate stacks. Surely this costs at least a little, and adds up with the number of threads?
I haven't read the post in detail though, thanks for the link! Seems interesting.
What's wrong with sending the sync code to a thread pool? My CPU-, disk- and database-intensive application is filled with calls like:
result = await asyncio.to_thread(long_function())
...and its resource usage and performance are great.The million threads risk slowing each other down with context switches, preventing any from finishing in time. An async event loop will focus on one connection at a time until `await`, and at least finish the tasks it attempts.
I haven't been in this situation, but async seems to have real advantages here. With OS threads, you don't control scheduling without costly synchronisation primitives.
I'd very much like a source for that, because I don't feel like it's very hard to understand.
> syntax like "async def" and "async with" makes you feel like you do, and stuff like FastAPI encourages you to type "async"
FastAPI's docs tell you to use "def" if you don't know what you're doing. [1] says "If you just don't know, use normal def."
It's also pretty simple, I think. If your function blocks, use "def", and let FastAPI run it in a thread pool to avoid blocking the event loop. If it doesn't block, use "async", and take advantage of concurrent execution without needing a new thread.
Isn't that by design? Sending CPU-heavy tasks to the default executor with asyncio.to_thread() works perfectly for me.
Or maybe this doesn't scale in your use-case, because of the thread count limit? (Although in that case, I don't think you'd be better off without asyncio.)
Same, but writing still helps me think better.
Maybe typing is too guided, and having to organise my thoughts on paper makes the process more efficient.
Some advantages: cancellation and error handling are trivial, there's no need for error-prone thread coordination, threads don't have to waste time waiting on locks (because we use asyncio sync primitives instead, so we don't submit work to a thread pool unless it's doable right now with no wait).
Of course, it depends on the tasks being written correctly. But "don't block the event loop" is a much easier rule to follow than "don't deadlock these 10 different threads that share queues and locks".
We didn't write an entire OS with it, but I don't think that was ever the point of asyncio, was it?