News for hackers. Stuff that matters.
Re:gh-116167: Allow disabling the GIL by behnamoh on Monday March 11, 2024 @01:08PM (#39670777)
I've been programming in Python for over 6 years now and every week I learn something new. But recently I've been thinking about moving to a more capable language with proper concurrency for backend API requests (FastAPI sucked).

I also want types, so Elixir is not in the picture. I dabbled in Rust a bit. Although I was able to get the hang of things and build a CLI tool pretty quickly, I'm worried I'll have to deal with numerous quirks later if I keep using Rust (like numerous string types). Is that something to be worried about if all I want from Rust is Python+Types+Concurrency?

Re:gh-116167: Allow disabling the GIL by spprashant on Monday March 11, 2024 @03:50PM (#39672513)
As someone in a similar boat, just pick Golang. People often dislike the basic syntax, explicit error checking and the lack of algebraic data types. I did. Rust just seems like it offers so much more and you fear missing out on something really cool.

But once you get over it, you realize Golang has a good type system, concurrency model, package manager that's not pip, fast compile times, and static binaries. For most cases it will also offer great performance.

It has everything you need to build APIs, CLI tools, web servers, microservices - pieces which will form the building blocks of your software infrastructure. I have heard numerous stories of people being productive in Go in a few days, sometimes even hours.

If Python is 0 quality of life and Rust is a 100, Golang gets you all they way up to 80-90. That last bit is something you might never need.

Rust is a great language and something I hope to be in proficient someday, but I ll save it for where I actually need that last microsecond of performance.

Re:gh-116167: Allow disabling the GIL by imbusy111 on Monday March 11, 2024 @01:12PM (#39670819)
Sounds like you want Julia. It looks like Python, but also has, what you ask for.

You can even run Python from Julia, so that alleviates the problem with a lack of libraries somewhat.

Re:gh-116167: Allow disabling the GIL by sparks1970 on Monday March 11, 2024 @01:15PM (#39670856)
Golang? Pretty easy to pick up coming from Python and proper concurrency.
Re:gh-116167: Allow disabling the GIL by scubbo on Monday March 11, 2024 @01:23PM (#39670956)
Python supports types! https://www.mypy-lang.org/
Re:gh-116167: Allow disabling the GIL by cmeacham98 on Monday March 11, 2024 @01:31PM (#39671042)
This seems a bit like saying "JavaScript supports types!" because of typescript.
Re:gh-116167: Allow disabling the GIL by ralphist on Monday March 11, 2024 @02:01PM (#39671394)
It's not a separate language, you can just start typing your programs right now.
Re:gh-116167: Allow disabling the GIL by nextlevelwizard on Monday March 11, 2024 @04:52PM (#39673107)
except nothing enforces your types at run time, you can have typi hints all you want and everyone else cn ignore them
Re:gh-116167: Allow disabling the GIL by aunderscored on Monday March 11, 2024 @05:57PM (#39673699)
Same exists with laws. And in most languages if I want to avoid the type system and hand you a goldfish instead of an int, I can. It just may take more effort. Other language will blow up too if you hand them strange things. Just like python those languages have ways to verify you're not passing goldfish, You just may need more or less effort to use them
Re:gh-116167: Allow disabling the GIL by nextlevelwizard on Tuesday March 12, 2024 @02:34AM (#39676747)
Thats a lot of words for: yeah, you are right
Re:gh-116167: Allow disabling the GIL by aunderscored on Tuesday March 12, 2024 @05:15PM (#39685049)
A lot of words for "yes, but all languages have this problem." The amount of effort to break the type system is the only difference.
Re:gh-116167: Allow disabling the GIL by nextlevelwizard on Wednesday March 13, 2024 @04:49PM (#39697305)
any type safe lnguage will indeed "blow up" while python just continues and you dont get as much as a warning. you are wrong take the L
Re:gh-116167: Allow disabling the GIL by ralphist on Tuesday March 12, 2024 @06:58AM (#39678100)
Everyone else can ignore every coding guideline your team sets up, that’s why code reviews and managers exist.
Re:gh-116167: Allow disabling the GIL by posix_monad on Monday March 11, 2024 @02:37PM (#39671821)
Types are way more mainstream in the JS ecosystem than they are in the Python ecosystem. If you want a "scripty" language with types, then TypeScript is a reasonable choice.
Re:gh-116167: Allow disabling the GIL by wiseowise on Monday March 11, 2024 @02:03PM (#39671422)
Both true. What’s wrong with them?
Re:gh-116167: Allow disabling the GIL by nick238 on Monday March 11, 2024 @05:15PM (#39673324)
Python actually has type safety though, as you can't do `'1' + 1` like in JS (not that a linter wouldn't scream at you). If I hear another "I compile <insert language> so I know it will work, but you can't do that in Python" I'll lose it. Having the compiler not complain that the types match is not effing "testing".
Re:gh-116167: Allow disabling the GIL by scubbo on Monday March 11, 2024 @06:32PM (#39673967)
> Having the compiler not complain that the types match is not effing "testing".

It absolutely is - it's just testing at a _very_ low level of correctness, and is not sufficient for testing actual high-level functionality.

Re:gh-116167: Allow disabling the GIL by docc on Monday March 11, 2024 @02:28PM (#39671729)
i moved from python timo Rust and i really like it. moving to a staticly typed language is bit of a mind fuck but cargo is amazing and so is the speed and portability of rust.
Re:gh-116167: Allow disabling the GIL by rightbyte on Monday March 11, 2024 @01:42PM (#39671160)
> Python+Types+Concurrency

Sounds like Groovy. But I wouldn't recommend it. Also the career padding hype is gone.

Re:gh-116167: Allow disabling the GIL by jondwillis on Monday March 11, 2024 @01:11PM (#39670811)
Swift or Kotlin might be what you’re looking for but nobody uses Swift for backend really, and I’m not sure about Kotlin.
Re:gh-116167: Allow disabling the GIL by kuschku on Monday March 11, 2024 @01:33PM (#39671070)
Kotlin has basically replaced java for many spring shops. It's really common in backend nowadays.
Re:gh-116167: Allow disabling the GIL by willcipriano on Monday March 11, 2024 @01:50PM (#39671259)
What sucked about FastAPI?
Re:gh-116167: Allow disabling the GIL by behnamoh on Monday March 11, 2024 @01:54PM (#39671306)
Not fast enough! I used it to call llama.cpp server but it would crash if requests were "too fast". Calling the llama.cpp server directly solved the issue.
Re:gh-116167: Allow disabling the GIL by ralphist on Monday March 11, 2024 @02:00PM (#39671383)
Did you get "connection reset by peer" when you sent a bit too many requests perchance? I've never found the source of that in my programs. There's no server logging about it, connections are just rejected. None of the docs talk about this.
Re:gh-116167: Allow disabling the GIL by behnamoh on Monday March 11, 2024 @02:11PM (#39671514)
I don't remember the exact error name but the FastAPI server would just freeze.
Re:gh-116167: Allow disabling the GIL by dekhn on Monday March 11, 2024 @03:11PM (#39672162)
a freeze is not a crash.
Re:gh-116167: Allow disabling the GIL by dumdedum on Monday March 11, 2024 @02:55PM (#39672005)
This sounds like a layer 8 problem
Re:gh-116167: Allow disabling the GIL by dekhn on Monday March 11, 2024 @01:57PM (#39671334)
Honestly, that doesn't sound right. I'm curious what you mean by crash thoguh.
Re:gh-116167: Allow disabling the GIL by KaiserPro on Monday March 11, 2024 @05:57PM (#39673701)
Interesting, I've used fastAPI to serve many thousands of requests a second (per process) for a production system. How were you buffering the requests?
Re:gh-116167: Allow disabling the GIL by jononor on Monday March 11, 2024 @09:00PM (#39674952)
You ran FastAPI app proper server like Uvicorn?
Re:gh-116167: Allow disabling the GIL by seabrookmx on Monday March 11, 2024 @07:16PM (#39674298)
GoLang as others suggested is a good pick. If you're in the "I don't like coloured functions" camp it's likely your best bet for web workloads.

If you're not a fan of GoLang's spartan syntax and are cool with async/await, C#/dotnet core is a great experience on all platforms. IMO it has the best async/await implementation (it originated there) on top of a multi-threaded event loop. ASP.NET is a great web framework and it has great library support for everything else. As someone who avoids "traditional" ORMs (Hybernate, Django) I really like Dapper.

Re:gh-116167: Allow disabling the GIL by neonsunset on Monday March 11, 2024 @08:25PM (#39674741)
Strong recommendation to look into ASP.NET Core with C#. It gives static typing, easy first-class concurrency, it runs on all platforms and now can be AOT compiled if that's your thing, if not - can still produce just a single executable if you choose to. Also its CLI is nice and similar to cargo. Naturally, you won't be having performance issues.
Re:gh-116167: Allow disabling the GIL by archargelod on Monday March 11, 2024 @09:59PM (#39675389)
You might wanna try Nim [0].

Nim is a statically-typed compiled language with very pythonic syntax. It's easy to learn, especially if you already know Python, because Nim's stdlib is heavily inspired by it.

For multithreading in Nim see:

Weave - https://github.com/mratsim/weave

Malebolgia - https://github.com/Araq/malebolgia

[0] - https://nim-lang.org

Re:gh-116167: Allow disabling the GIL by agacera on Tuesday March 12, 2024 @09:46AM (#39679429)
DevX in Rust for backend development is quite good nowadays. Things are WAY easier than it was a couple of years ago.

I migrated a couple of projects from Java, TS and Go to Rust and honesly, I couldn't be happier.