In case you want to do it using Python: check Is it possible in python to kill process that is listening on specific port, for example 8080?
The answer from Smunk works nicely. I repeat his code here:
from psutil import process_iter
from signal import SIGTERM # or SIGKILL
for proc in process_iter():
for conns in proc.connections(kind='inet'):
if conns.laddr.port == 8080:
proc.send_signal(SIGTERM) # or SIGKILL
continue