News for hackers. Stuff that matters.
Re:We have to talk about this Python, Gunicorn, Gevent thing by shakna on Saturday March 07, 2020 @10:56PM (#22516255)
> The author seems to be saying something about how if a worker is busy doing CPU intensive work (is decoding JSON really that intensive?) then other requests accepted by that worker have to wait for that work to complete before they can respond, and the client might timeout while waiting?

Yes. Decoding JSON with Python is CPU-intensive.

This a very simple shell script around Python, that is designed from the get-go to crash with an exception. However, it may not be the exception you expect:

    n="$(python3 -c 'import math; import sys; sys.stdout.write(str(math.floor(sys.getrecursionlimit() - 4)))')"
    left="$(yes [ | head -n "$n" | tr -d '\n')"
    echo "$left" | python3 -c 'import json; print(json.loads(input()))'
Python's docs suggest you should arrive at one of two errors here: MemoryError (We are trying to parse something sizeable) or json.DecodeError (The JSON is invalid).

You won't. You'll hit RecursionError.

Because, despite how badly Python deals with recursion, the JSON library depends on it extensively. Which means that there is a huge stack-tree being built every time you try and decode JSON in Python (Dictionaries, function call overhead, etc, etc.), only for it to be thrown away.

There are no comments on this comment yet.