python3 报错 [Errno 5] Input/output error 没有stdout时使用了print

本文描述了在使用Tornado框架开发的项目中,遇到的后台运行时因远程SSH连接关闭导致的I/O错误问题。详细介绍了问题的原因在于程序中的print语句在失去shell后无法输出,给出了三种解决方案:通过crontab定时启动、注释或删除print语句、使用nohup命令运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

过程描述

刚不久用 Tornado 写了一个项目,本打算部署在 Nginx 上,但是因为公司的一些原因就没有使用 Nginx,直接在命令行中启动

当我从命令行以后台的方式启动以后,是可以正常访问的

python start.py &

但是,当我关闭远程 ssh 连接后,程序就出问题了,程序没有任何反应,但是进程却好好的待在进程池中等待 CPU 的召唤。通过 try 捕获到了异常 [Errno 5] Input/output error

后经过排查找到了问题,这是因为我在程序中有 print 语句,当我把远程 ssh 退出后,就相当于把它的 shell 关闭了,没有了 shell 的进程 print 就没有地方输出字符,不能“写”到屏幕上了,所以就会报一个 I/O 错误

解决方案

  1. 不使用命令行的方式启动,将程序放入 crontab 中定时启动

  2. 注释或删除程序中有 print 语句的地方

  3. 使用 nohup 运行命令,可以使命令永久的执行下去,和用户终端没有关系,断开SSH连接都不会影响程序的运行

 

Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/24/3c/4475aebeaab9651f2e61000fbe76f91a476d371dbfbf0a1cf46e689af253/cuda_python-12.9.0-py3-none-any.whl (7.5 kB) Collecting flashinfer_python==0.2.7.post1 (from sglang[srt]>=0.4.2.post4; sys_platform == "linux" and extra == "all"->xinference[all]) Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/c0/10/43cf1ea7a03ca8e75a185190708e48286e1583d781e93d1de130e5d450ca/flashinfer_python-0.2.7.post1.tar.gz (3.2 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [25 lines of output] 0 AOT ops found in /tmp/pip-install-5miuve_d/flashinfer-python_eff3c7d3d9c144ef8d5b1795255a9142/aot-ops Traceback (most recent call last): File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "/tmp/pip-install-5miuve_d/flashinfer-python_eff3c7d3d9c144ef8d5b1795255a9142/custom_backend.py", line 91, in prepare_metadata_for_build_wheel return orig.prepare_metadata_for_build_wheel(metadata_directory, config_settings) File "/tmp/pip-build-env-nmvsvfk_/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() File "/tmp/pip-build-env-nmvsvfk_/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 89, in <module> File "<string>", line 86, in get_cuda_version File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 503, in run with Popen(*popenargs, **kwargs) as process: File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 971, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 1863, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: &#39;:/usr/local/cuda-12.2/bin/nvcc&#39; [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. 帮我分析一下报错
最新发布
07-17
Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/c0/10/43cf1ea7a03ca8e75a185190708e48286e1583d781e93d1de130e5d450ca/flashinfer_python-0.2.7.post1.tar.gz (3.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 906.0 kB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [25 lines of output] 0 AOT ops found in /tmp/pip-install-0xzswk27/flashinfer-python_efcdfa3e94c64419bf5a1ddd6c860ff4/aot-ops Traceback (most recent call last): File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/data/anaconda3/envs/xinference/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "/tmp/pip-install-0xzswk27/flashinfer-python_efcdfa3e94c64419bf5a1ddd6c860ff4/custom_backend.py", line 91, in prepare_metadata_for_build_wheel return orig.prepare_metadata_for_build_wheel(metadata_directory, config_settings) File "/tmp/pip-build-env-udwbin8_/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() File "/tmp/pip-build-env-udwbin8_/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 89, in <module> File "<string>", line 86, in get_cuda_version File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 503, in run with Popen(*popenargs, **kwargs) as process: File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 971, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/data/anaconda3/envs/xinference/lib/python3.10/subprocess.py", line 1863, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: &#39;:/usr/local/cuda-12.2/bin/nvcc&#39; [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. 分析一下
07-16
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值