Tayfun Akgüç Tayfun Akgüç - 1 month ago 5x
Python Question

Python script uses 100% CPU

Hey I was working with python. In my python file I just have 2 lines like :


and I make my .py file executable and run it(./hello.py) on ubuntu server.
With "top" command, i listed all processes.
hello.py uses 100% CPU.
Why it use 100% CPU(Server has 512MB 1 CPU)


Your incorrect shebang line of


causes the system to launch /usr/bin/env to handle the script, as follows:

/usr/bin/env ./hello.py

/usr/bin/env treats the first argument not containing = and not starting with - as a program to run, so it tries to launch ./hello.py. Due to the incorrect shebang line, this once again runs

/usr/bin/env ./hello.py

It's an infinite loop.