Python错误:close failed in file object destructor

本文探讨了二进制程序调用shell再调用Python时遇到的问题,即shell退出后Python进程仍挂起,并给出了可能的原因及解决建议。
AI助手已提取文章相关产品:

我遇到的情况: 
二进制程序调shell再调Python后,shell退出,Python进程挂到init上(不是僵尸进程),但 
此时二进制程序未退出,这时候中断而二进制程序出现此提示。

经查询: 
应该是Python程序的stdout出错,最好输出到文件,不要输出到stdout。 
其次,也可以忽略此信息,不会影响程序运行。

参考:https://github.com/jeroenjanssens/data-science-at-the-command-line/issues/35

转载于:https://www.cnblogs.com/willaty/p/8005551.html

您可能感兴趣的与本文相关内容

``` [root@b9feba924e07 finetune]# python device.py DrvMngGetConsoleLogLevel failed. (g_conLogLevel=3) [ERROR] ATRACE(1409,python):2025-08-20-06:20:11.265.654 [trace_driver_api.c:56](tid:1409) get platform info failed, drvErr=87. [EVENT] PROFILING(1409,python):2025-08-20-06:20:11.269.368 [msprof_callback_impl.cpp:358] >>> (tid:1409) Started to register profiling ctrl callback. [EVENT] PROFILING(1409,python):2025-08-20-06:20:11.269.662 [msprof_callback_impl.cpp:365] >>> (tid:1409) Started to register profiling hash id callback. [INFO] PROFILING(1409,python):2025-08-20-06:20:11.269.746 [prof_atls_plugin.cpp:117] (tid:1409) RegisterProfileCallback, callback type is 7 [EVENT] PROFILING(1409,python):2025-08-20-06:20:11.269.815 [msprof_callback_impl.cpp:372] >>> (tid:1409) Started to register profiling enable host freq callback. [INFO] PROFILING(1409,python):2025-08-20-06:20:11.269.881 [prof_atls_plugin.cpp:117] (tid:1409) RegisterProfileCallback, callback type is 8 [INFO] RUNTIME(1409,python):2025-08-20-06:20:11.272.021 [task_fail_callback_data_manager.cc:58] 1409 TaskFailCallBackManager: Constructor. [INFO] HCCL(1409,python):2025-08-20-06:20:11.343.120 [adapter_rts.cc:2720] [1409][adapter_rts.cc][CallBackInitRts] g_deviceType [6] g_deviceLogicId [-1] g_devicePhyId [-1] [INFO] PROFILING(1409,python):2025-08-20-06:20:11.795.995 [prof_atls_plugin.cpp:210] (tid:1409) Module[0] register callback of ctrl handle. [INFO] PROFILING(1409,python):2025-08-20-06:20:11.935.496 [prof_atls_plugin.cpp:210] (tid:1409) Module[61] register callback of ctrl handle. /usr/local/python3.10.17/lib/python3.10/site-packages/torch_npu/npu/__init__.py:371: UserWarning: Can't get ascend_hal device count warnings.warn("Can't get ascend_hal device count") [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.011.311 [runtime_keeper.cc:66]1409 GetDeviceType:Call halGetDeviceInfo failed: drvRet=87, module type=0, info type=1. [INFO] RUNTIME(1409,python):2025-08-20-06:20:12.015.229 [runtime_keeper.cc:149] 1409 CreateRuntimeImpl: Open libruntime_v100.so success [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.050.017 [runtime.cc:1380]1409 CheckHaveDevice:Call halGetDeviceInfo failed: drvRet=87, module type=0, info type=1. [INFO] PROFILING(1409,python):2025-08-20-06:20:12.050.812 [prof_atls_plugin.cpp:210] (tid:1409) Module[7] register callback of ctrl handle. [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.051.003 [driver.cc:65]1409 GetDeviceCount:Call drvGetDevNum, drvRetCode=87. [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.051.116 [api_c_device.cc:23]1409 rtGetDeviceCount:ErrCode=507899, desc=[driver error:internal error], InnerCode=0x7020010 [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.051.187 [error_message_manage.cc:53]1409 FuncErrorReason:report error module_type=3, module_name=EE8888 [ERROR] RUNTIME(1409,python):2025-08-20-06:20:12.051.257 [error_message_manage.cc:53]1409 FuncErrorReason:rtGetDeviceCount execute failed, reason=[driver error:internal error] [ERROR] ASCENDCL(1409,python):2025-08-20-06:20:12.051.369 [device.cpp:341]1409 aclrtGetDeviceCount: get device count failed, runtime result = 507899. [INFO] RUNTIME(1409,python):2025-08-20-06:20:12.052.006 [api_impl.cc:7464] 1409 PeekLastErr: level=0 err=507899. [ERROR] APP(1409,python):2025-08-20-06:20:12.052.092 [log_inner.cpp:76]1409 build/CMakeFiles/torch_npu.dir/compiler_depend.ts:device_count:27: "[PTA]:"get device count of NPU failed"" NPU设备不可用! [INFO] RUNTIME(1409,python):2025-08-20-06:20:13.126.055 [runtime.cc:1540] 1409 ~Runtime: deconstruct runtime [INFO] RUNTIME(1409,python):2025-08-20-06:20:13.149.326 [runtime.cc:1547] 1409 ~Runtime: wait monitor success, use=0. [INFO] RUNTIME(1409,python):2025-08-20-06:20:13.171.425 [task_fail_callback_data_manager.cc:63] 1409 ~TaskFailCallBackManager: Destructor. [root@b9feba924e07 finetune]# touch device2.py [root@b9feba924e07 finetune]# vim device2.py [root@b9feba924e07 finetune]# python device2.py DrvMngGetConsoleLogLevel failed. (g_conLogLevel=3) [ERROR] ATRACE(1477,python):2025-08-20-06:21:39.762.176 [trace_driver_api.c:56](tid:1477) get platform info failed, drvErr=87. [EVENT] PROFILING(1477,python):2025-08-20-06:21:39.765.717 [msprof_callback_impl.cpp:358] >>> (tid:1477) Started to register profiling ctrl callback. [EVENT] PROFILING(1477,python):2025-08-20-06:21:39.766.018 [msprof_callback_impl.cpp:365] >>> (tid:1477) Started to register profiling hash id callback. [INFO] PROFILING(1477,python):2025-08-20-06:21:39.766.106 [prof_atls_plugin.cpp:117] (tid:1477) RegisterProfileCallback, callback type is 7 [EVENT] PROFILING(1477,python):2025-08-20-06:21:39.766.175 [msprof_callback_impl.cpp:372] >>> (tid:1477) Started to register profiling enable host freq callback. [INFO] PROFILING(1477,python):2025-08-20-06:21:39.766.239 [prof_atls_plugin.cpp:117] (tid:1477) RegisterProfileCallback, callback type is 8 [INFO] RUNTIME(1477,python):2025-08-20-06:21:39.768.477 [task_fail_callback_data_manager.cc:58] 1477 TaskFailCallBackManager: Constructor. [INFO] HCCL(1477,python):2025-08-20-06:21:39.838.567 [adapter_rts.cc:2720] [1477][adapter_rts.cc][CallBackInitRts] g_deviceType [6] g_deviceLogicId [-1] g_devicePhyId [-1] [INFO] PROFILING(1477,python):2025-08-20-06:21:40.274.132 [prof_atls_plugin.cpp:210] (tid:1477) Module[0] register callback of ctrl handle. [INFO] PROFILING(1477,python):2025-08-20-06:21:40.427.840 [prof_atls_plugin.cpp:210] (tid:1477) Module[61] register callback of ctrl handle. 2.5.1.post1.dev20250619 /usr/local/python3.10.17/lib/python3.10/site-packages/torch_npu/npu/__init__.py:371: UserWarning: Can't get ascend_hal device count warnings.warn("Can't get ascend_hal device count") [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.501.385 [runtime_keeper.cc:66]1477 GetDeviceType:Call halGetDeviceInfo failed: drvRet=87, module type=0, info type=1. [INFO] RUNTIME(1477,python):2025-08-20-06:21:40.505.624 [runtime_keeper.cc:149] 1477 CreateRuntimeImpl: Open libruntime_v100.so success [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.541.279 [runtime.cc:1380]1477 CheckHaveDevice:Call halGetDeviceInfo failed: drvRet=87, module type=0, info type=1. [INFO] PROFILING(1477,python):2025-08-20-06:21:40.542.034 [prof_atls_plugin.cpp:210] (tid:1477) Module[7] register callback of ctrl handle. [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.542.214 [driver.cc:65]1477 GetDeviceCount:Call drvGetDevNum, drvRetCode=87. [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.542.313 [api_c_device.cc:23]1477 rtGetDeviceCount:ErrCode=507899, desc=[driver error:internal error], InnerCode=0x7020010 [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.542.384 [error_message_manage.cc:53]1477 FuncErrorReason:report error module_type=3, module_name=EE8888 [ERROR] RUNTIME(1477,python):2025-08-20-06:21:40.542.452 [error_message_manage.cc:53]1477 FuncErrorReason:rtGetDeviceCount execute failed, reason=[driver error:internal error] [ERROR] ASCENDCL(1477,python):2025-08-20-06:21:40.542.554 [device.cpp:341]1477 aclrtGetDeviceCount: get device count failed, runtime result = 507899. [INFO] RUNTIME(1477,python):2025-08-20-06:21:40.543.254 [api_impl.cc:7464] 1477 PeekLastErr: level=0 err=507899. [ERROR] APP(1477,python):2025-08-20-06:21:40.543.337 [log_inner.cpp:76]1477 build/CMakeFiles/torch_npu.dir/compiler_depend.ts:device_count:27: "[PTA]:"get device count of NPU failed"" 0 [INFO] RUNTIME(1477,python):2025-08-20-06:21:41.313.007 [runtime.cc:1540] 1477 ~Runtime: deconstruct runtime [INFO] RUNTIME(1477,python):2025-08-20-06:21:41.336.892 [runtime.cc:1547] 1477 ~Runtime: wait monitor success, use=0. [INFO] RUNTIME(1477,python):2025-08-20-06:21:41.368.796 [task_fail_callback_data_manager.cc:63] 1477 ~TaskFailCallBackManager: Destructor. ``` import torch_npu print(torch_npu.__version__) print(torch_npu.npu.device_count()) # 应该输出大于0的值 指定这段代码,报错如上
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值