Tayfun Akgüç Tayfun Akgüç - 1 year ago 141
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)

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download