You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下Python3用Flask-RESTful遇OSError[Errno98]及内核进程退出求助

Fixing OSError: Errno 98 (Address in Use) and GLib-GIO Warning in Flask + Miniconda Setup

Alright, let's work through this problem step by step. You've got two key things going on here: that persistent port conflict error, plus the GLib-GIO warning that popped up after killing your Python process. Let's tackle them one by one, starting with the port issue since it's blocking your Flask app from running.

1. Resolve the "Address already in use" Error

This is the critical blocker—here are the most reliable fixes:

Option 1: Find and fully kill the process holding the port

Sometimes netstat might miss lingering processes, so use lsof (more precise for tracking open ports/files) to get the exact process ID:

  • First, check which process is using Flask's default port (replace 5000 with your actual port if you changed it):
    lsof -i :5000
    
  • Locate the PID column in the output, then force-kill the process to ensure it doesn't linger:
    kill -9 <PID>
    
    The -9 flag skips graceful shutdown, which is perfect for stubborn Flask debug-mode child processes that often stick around.

Option 2: Run Flask on a different port

If killing processes feels tedious, just switch to an unused port directly:

  • In your Flask code, modify the app.run() line:
    if __name__ == '__main__':
        app.run(port=5001)  # Use any free port (e.g., 5001, 8080)
    
  • Or if you're using the Flask CLI, run:
    flask run --port 5001
    

Option 3: Check Flask's Debug Mode

If you're running with debug=True, Flask spawns a child process for auto-reloading. This child can stay alive even after you kill the main process, hogging the port. Try:

  • Temporarily disabling debug mode to test: app.run(debug=False)
  • If you need debug mode, use lsof to find all PIDs linked to the port and kill every single one.

2. Fix the GLib-GIO Warning

This warning is just a nuisance (it doesn't break your Flask app) but it's easy to fix permanently:

  • The message means your Miniconda environment isn't accessing the system's GSettings modules correctly. Your export command is valid, but make sure you run it after activating your Miniconda environment.
  • To make this setting permanent, add the export to your environment's activation script:
    1. Create the activation script directory if it doesn't exist:
      mkdir -p ~/.conda/envs/<your-env-name>/etc/conda/activate.d
      
    2. Create a script (e.g., set_gio_modules.sh) inside that directory with:
      export GIO_EXTRA_MODULES=/usr/lib/x86_64-linux-gnu/gio/modules/
      
    Now every time you activate your Miniconda environment, this variable will be set automatically, and the warning should disappear.

内容的提问来源于stack exchange,提问作者Jay Cho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:51:31