111 points · by chmaynard · 6y ago · 57 comments
This is poking fun at Windows' PATH_MAX, but it's very easy to hit BINPRM_BUF_SIZE's 128 character path limit for #! lines; maybe not so much for humans, but with CI systems installing things in weird deep directories (e.g. virtualenvs ... see https://github.com/pypa/virtualenv/issues/596).
So the old adage about glass houses and stones is still good advice ;)
Then the npm<3 install modules in a dawn nested way and actually cause problem.
- max size of a command line
- max open files
- kernel stack size
etc...
Nope. One guy randomly wants to arbitrarily limit random Python things to 1000000, cite vague optimization potential advantages (in CPython, yeah, right...), and doesn't even want to detail the impact of said optims when further asked.
IMO this is just a waste of time for everybody and should be firmly rejected ASAP. Even just proposing to limit to 1M "source" lines is extremely naive and the sign of somebody without much real world experience: there are many cases when "source" code is not the actual source, and has orders of magnitude more lines.
Correctness when you have arbitrarily long input gets complicated very easily. I was originally skeptical when reading, it seemed ridiculous and arbitrary, until I realized that’s what they were going for.
There are a myriad of better ways to improve Python and this isn't it.
Indeed. Accepting arbitrary inputs frequently requires an arbitrary amount of resources. Even if there are no vulnerabilities to exploit, a denial of service attack may still be possible because processing untrusted input can result in massive memory allocations.
A concrete example I've recently dealt with:
https://github.com/multiformats/unsigned-varint/blob/master/...
These variable length integers may consume an unbounded amount of memory when decoded. I think it's wise to constrain this by default and let the caller increase or turn off the limits if they want:
decode(buffer) # max=9, per spec
decode(buffer, max=64)
decode(buffer, max=math.inf)> Picking an arbitrary limit less than 232 is certainly safer for many reasons, and very unlikely to impact real usage. We already have some real limits well below 106 (such as if/else depth and recursion limits).
> A range of -1,000,000 to 1,000,000 could fit in 21 bits and that three of those values could be packed into a 64-bit word.
In theory this could bring security and performance benefits. In practice if you claim to be limited by MAX_UINT you're likely to encounter issues if you try to close to that limit without very careful coding around overflow.
https://github.com/vindarel/languages-that-compile-to-python
This change is almost guaranteed to break most of these.
* The steering council decided that they will make the final decision on it directly. [1]
* Their has definitely been a less than enthusiastic response from the python devs overall and some of the steering council members specifically, including GVR [2]
[1] https://mail.python.org/archives/list/python-dev@python.org/... [2] https://mail.python.org/archives/list/python-dev@python.org/...
N = int(1E6)
for x in range(N):
print (f"x{x}={x}")
generates lines like: x0=0
x1=1
x2=2
...
running it with: time python big.py
takes just 5 seconds - I am impressed! Maybe the limit is too low. N = 1E6.to_int
N.times { |i| puts "x#{i} = #{i}" }
Then running it with: time ruby big.rb
It never completed, because it allocates variables on stack. Traceback (most recent call last):
big.rb: stack level too deep (SystemStackError)
ruby big.rb 1451.52s user 23.74s system 97% cpu 25:08.23 totalProgram for reference.
use strict;
use warnings;
my $max_i = 1_000_000;
for my $i (0 .. $max_i) {
print "my \$x$i = $i;\n";
}
Edit: It took 80 minutes! Wow. There must be something significantly different going on, but I wouldn't know where to look.Having said that, the fact it takes 5 seconds is pretty arbitrary—we can't really say it's good or bad unless there is some basis for comparison.
python generate.py > big.py
then this file was executed with Python, that took 5 seconds: time python big.py
and yes, I had no idea what to expect, hence the test.Remember that before Unix file system used to enforce what’s in the file instead of allowing storing whatever in whatever? That specific suffix/file validation that are carried in part on early Windows? People were sufficiently pissed to create Unix, which had none such bs.
Less rule is better than more rules, You can always put whatever you want into best practice but not expect people to follow hidden rules like this one.
Pypy is in a spot where if you're after speed you would do it in another language, while package accessibility that cpython has is gone. I don't see it going mainstream but it's a nice project - and I can see why it has more limitation.
Don't see it as a forced rule to restrict people, I can't really see how 1 million lines is a restriction on hand writen code anyways and generators can work around the problem, but more as a contract that sets the boundary on what people can expect. Python interpreter developers know they don't have to expect arbitrary large programs and can optimize their code for everything below 1 million and Python scripts/app developers know within what limits they can expect their code to work.
Unix didn't limit what you can put in a file, it doesn't expect your program to work when you fill your program with random strings.
The point is, the intepreter developer can feel free to optimize for everything below 1 million, putting a hard cap is pointless. The same reason that most sh file are suffixed as sh despite not needing that suffix at all.
The proposal: https://lwn.net/ml/python-dev/93cf822c-4d67-b8f7-1d91-7d8053... ([Python-Dev] PEP proposal to limit various aspects of a Python program to one million. )
I don't know why people would assume that's enough of a limit if there really isn't a need to limit that aspect.
8 maximum parameters on a function
96 maximum constants
32 max globals
24 max locals
The self flagellating q developer will enjoy these limits under the guise of good coding practice enforcement (if you have more than 24 variables in your function, you should split your function up)1: Table of Limit Errors at http://www.timestored.com/kdb-guides/kdb-database-limits#con...