I have also encounter the same problem, i have used ESP IDE. Actually you have to close the terminal by ctrl+] in terminal itself. Then the terminal is closed.