Linux下Python3用Flask-RESTful遇OSError[Errno98]及内核进程退出求助
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
5000with your actual port if you changed it):lsof -i :5000 - Locate the
PIDcolumn in the output, then force-kill the process to ensure it doesn't linger:
Thekill -9 <PID>-9flag 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
lsofto 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
exportcommand 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:
- Create the activation script directory if it doesn't exist:
mkdir -p ~/.conda/envs/<your-env-name>/etc/conda/activate.d - 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/
- Create the activation script directory if it doesn't exist:
内容的提问来源于stack exchange,提问作者Jay Cho

