퐈니썬's LIfe - 잘 실패하자 RSS 태그 관리 글쓰기 방명록
2021-12-23 16:04:32
728x90
반응형

Python Flask를 Docker로 여러가지 테스트를 하다가, 로컬에서 flask run을 했는데 다음과 같은 에러코드를 확인하게 되었다. 

 

Flask에서 5000 port 를 사용하는데, 테스트 하다가 Flask가 비정상 종료되어 5000 port 에 계속 머물고 있는 경우 발생한다. 

 

 

에러 메세지

[hwan@localhost Flask]$ flask  run
 * Environment: development
 * Debug mode: on
Traceback (most recent call last):
  File "/usr/local/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 860, in run_command
    extra_files=extra_files,
  File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 1030, in run_simple
    s.bind(server_address)
OSError: [Errno 98] Address already in use

 

해결방안

비정상된 process를 찾아 종료하면된다. 

flask process 찾기

[hwan@localhost Flask]$ sudo lsof -i :5000
[sudo] password for hwan: 
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
flask   32552 hwan    3u  IPv4 8675846      0t0  TCP localhost:commplex-main (LISTEN)
python3 32558 hwan    3u  IPv4 8675846      0t0  TCP localhost:commplex-main (LISTEN)
python3 32558 hwan    5u  IPv4 8675846      0t0  TCP localhost:commplex-main (LISTEN)

flask process 종료하기

[hwan@localhost Flask]$ sudo kill -9 32552 32558

flask 다시 실행

[hwan@localhost Flask]$ flask run
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 291-959-067
728x90
반응형