How to I close down a python server built using flask
You will have another process listening on port 8080. You can check to see what that is and kill it. You can find processes listening on ports with netstat -tulpn. Before you do that, check to make sure you don't have another terminal window open with the running instance.
When I run this simple code:
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
    return 'this is the homepage'
if __name__ ==  "__main__":
    app.run(debug=True, host="0.0.0.0",port=8080)
It works fine but when I close it using ctrl+z in the terminal and try to run it again I get OSError: [Errno 98] Address already in use
So I tried changing the port address and re-running it which works for some of the port numbers I enter. But I want to know a graceful way to clear the address being used by previous program so that it is free for the current one. 
Also is what is the apt way to shutdown a server and free the port address.
Kindly tell a simple way to do so OR explain the method used fully because I read solutions to similar problems but didn't understand any of it.
When I run
netstat -tulpn
The output is : 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:3689            0.0.0.0:*               LISTEN      4361/rhythmbox
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
tcp6       0      0 :::3689                 :::*                    LISTEN      4361/rhythmbox
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           3891/chrome
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
udp        0      0 0.0.0.0:39223           0.0.0.0:*                           -
udp        0      0 127.0.1.1:53            0.0.0.0:*                           -
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -
udp        0      0 0.0.0.0:58140           0.0.0.0:*                           -
udp6       0      0 :::5353                 :::*                                3891/chrome
udp6       0      0 :::5353                 :::*                                -
udp6       0      0 :::41938                :::*                                -
I'm not sure how to interpret it.    
the output of ps aux | grep 8080 
is :
shreyash 22402  0.0  0.0  14224   928 pts/2    S+   01:20   0:00 grep --color=auto 8080
I don't know how to interpret it.
Which one is the the process name and what is it's id?