6 ms·
Here's the justification for removing cgi - https://peps.python.org/pep-0594/#cgi https://peps.python.org/pep-0594/#cgi Amusingly that links to https://peps.py
by simonw 1y ago
Here's the justification for removing cgi - https://peps.python.org/pep-0594/#cgi https://peps.python.org/pep-0594/#cgi
Amusingly that links to https://peps.python.org/pep-0206/ https://peps.python.org/pep-0206/ from 14th July 2000 (25 years ago!) which, even back then, described the cgi package as "designed poorly and are now near-impossible to fix".
Looks like the https://github.com/jackrosenthal/legacy-cgi https://github.com/jackrosenthal/legacy-cgi package provides a drop-in replacement for the standard library module.
- kragen 1y agoThat fails pretty hard at providing a rationale. Basically it says that CGI is an inefficient interface because it involves creating a new process! Even if that were true, "You shouldn't want to do such an inefficient thing" is very, very rarely a reasonable answer to a technical question like "How do I write a CGI script in Python?" or "How do I parse a CSV file in Python?" There are certainly some suboptimal design choices in the cgi module's calling interface, things you did a much better job of in Django, but what made them "near-impossible to fix" was that at the time everyone reading and writing PEPs considered backwards compatibility to be not a bad thing, or even a mildly good thing, but an essential thing that was worth putting up with pain for. Fixing a badly designed interface is easy if you know what it should look like and aren't constrained by backwards compatibility.
- simonw 1y agoThe main rationale is earlier in the PEP: https://peps.python.org/pep-0594/#rationale https://peps.python.org/pep-0594/#rationale
- deleted 1y ago[deleted]
- kragen 1y agoRight. Isn't that insane? If I hadn't found it by means of having modules removed that my code depended on, I would have thought it was satire. That policy, and the heinous character assassination the PSF carried out against Tim Peters, mean I can no longer recommend in good conscience that anyone adopt Python.
- hot_gril 1y agoIdk about the internal affairs, I just really don't like Python for web backend kind of things. It's taking them way too long to sort out parallelism and packaging, while NodeJS got both right from the start and gracefully upgraded (no 2->3 mess). Also I used Python way before JS, and I still like JS's syntax better. Especially not using whitespace for scope, which makes even less sense in a scripting language since it's hard to type that into a REPL.
- kragen 1y agoYeah, generally I feel like the indentation sensitivity was the right idea (the alternative evidently being worse compiler error messages, bugs like the `goto fail` vulnerability, and greater verbosity) but it causes real difficulties with the REPL, as well as with shell one-liners. Jupyter fixes the REPL problem, and it's a major advance in REPLs in a number of other ways, but it has real problems of its own.
- eurleif 1y agoNode.js actually had no parallelism at the start, other than the ability to manually spawn new processes. Worker threads were only added in 2018 with v10.5.0, and only stabilized in 2019 with v12. What Node.js had from the start was concurrency via asynchronous IO. And before Node.js was around to be JavaScript's async IO framework, there was a robust async IO framework for Python called Twisted. Node.js was influenced by Twisted[0], and this is particularly evident in the design of its Promise abstraction (which you had to use directly when it was first released, because JavaScript didn't add the async/await keywords until years later). [0] https://nodejs.org/en/about https://nodejs.org/en/about
- frollogaston 1y agoI was referring to the async io from the start, not worker threads. Other langs had their own frameworks for this, including Twisted for Python, but it really makes a difference having that stuff built-in and default.
- stefan_ 1y agoIt seems Python has firmly reached its "Wikipedia notability" era, with busybodies that code little but discuss much dominating and ruining all progress. They make up stuff that reads insane to anyone doing actual work, like the "maintenance burden" of the cgi module: https://github.com/python/cpython/commits/3.12/Lib/cgi.py https://github.com/python/cpython/commits/3.12/Lib/cgi.py Turns out most maintenance this thing received is the various attempts of removing it.
- riedel 1y agoMoving stuff out of the standard library seems like a reason. However, I think this all is a weird mix of arguments. IMHO new process spawning is a feature and not a bug in the use cases where CGI is used. Most of the stuff is low traffic config interfaces or remote invocable scripts. There was this trend to move stuff to fcgi. We had tons of cases of memory leaks in long running but really seldomly used stuff like mailing list servers. To me cgi is the poor man's alternative to serverless. However, I also do not really completely understand why a standard library has to support it. I have bash scripts running using the Apache CGI mod.
- kragen 1y agoI would have phrased it, "serverless is a marketing term for CGI scripts." I have bash CGI scripts too, though Shellshock and bash's general bug-proneness make me doubt that this was wise. There are some advantages of having the CGI protocol implemented in a library. There are common input-handling bugs the library can avoid, it means that simple CGI programs can be really simple, and it lets you switch away from CGI when desired. That said, XSS was a huge problem with really simple CGI programs, and an HTML output library that avoids that by default is more important than the input parsing—another thing absent from Python's standard library but done right by Django.
- chgs 1y agoI used bash cgi scripts all the time. Haven’t used a python cgi module but the main benefit of perl’s cgi module (also removed) is the query parameter parsing.
- kragen 1y agoI think CGI.pm is still in CPAN? It was never in the Perl standard library, was it? As mentioned elsewhere in the thread, the query parameter parsing is still in the Python standard library, just invoked differently.
- hwj 1y agoYes, it's still in CPAN, but previously it was in the standard library.
- pjmlp 1y agoNot to mention that if efficiency is a goal, probably Python isn't the language as well, so it is a very strange argument from Python developers.
- kragen 1y agoIt would have been a less strange argument 25 years ago, before the manycore era, when using Python involved less of a performance sacrifice. And there are still cases where Python is acceptably performant. However, the argument is from only 6 years ago, which makes it ridiculous.
- jwatte 1y agoPython is still a 10x or more performance sacrifice for anything that's actually CPU throughput limited. Or, alternatively, your VM hosting cost will be 10x larger on Python, than something top of the line, if your workload is CPU throughput limited. Whether you're actually CPU limited, and whether VM hosting costs is your largest cost, is a totally different question :-)
- kragen 1y agoTypically, computation you do in Python code costs you about 40× as much CPU as if you did it in C. But with Numpy I usually see only about a 4× single-core slowdown after a little optimization work. Many database-backed web services are bottlenecked on the database or text template instantiation, neither of which are really related to Python's CPU efficiency. As a side note, the most popular databases are getting only a tiny fraction of the available performance on current hardware. I wrote a couple of comments with more details about this a week ago: https://news.ycombinator.com/item?id=44408654 https://news.ycombinator.com/item?id=44408654 In the manycore world, Python's GIL makes some approaches to scaling across cores unavailable, though that is changing. But I don't think those are usually relevant to web server throughput, just (potentially) latency.
- IgorPartola 1y ago