Difference between running a python script locally vs in docker

I wrote a code to produce memory error but while I run it locally on my machine (i.e Mac OS) I am able to get memory error but while I run this code inside docker python container with limited ram assigned it doesn’t throw any error. I don’t know why. Sorry if you find this lame.

Here is the code:

def str_append(s):
    output = ''
    i = 0
    for i in range(100000000000000000):
        output += s
        i = i + 1
    print(sys.getsizeof(output))
    return output.encode('latin1')
print(str_append(string).decode('latin1'))

Docker file code

FROM python:3.6

WORKDIR /usr/src/app

# Bundle app source
COPY /test2.py .

EXPOSE 8080

CMD ["python", "test2.py"]

First I build the image with docker build -t mypytest .

After that I run it with docker run -m=23M -memory-swap=30M mypytest

But it hangs without producing any output, when I check the stats:
Docker Stats After Running The Image

Source: StackOverflow