请教下开发python后端服务的一些问题
-
首先,你要开发一个 http 服务, 把想提供给前端的接口写好。 然后,按照这个文档的说明打包服务(https://docs.airiot.link/development-manual/sdk/develop_service#3-编写-serviceyml 注意: service.yml 文件的内容), 然后把服务部署到平台中, 然后就可以通过平台 /rest/{service.yml文件中的 Path}/接口路径访问到你自己开发的服务了
-
@chenpengchao@Yoki 我的服务本地测试正常,上传到平台后,一直显示重启中是什么原因
日志报错
]OpenBLAS blas_thread_init: pthread_create failed for thread 1 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 2 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 3 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 4 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 5 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 6 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 7 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 8 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
]OpenBLAS blas_thread_init: pthread_create failed for thread 9 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 10 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 11 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 12 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 13 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 14 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
^OpenBLAS blas_thread_init: pthread_create failed for thread 15 of 16: Operation not permitted
nOpenBLAS blas_thread_init: ensure that your address space and process count limits are big enough (ulimit -a)
eOpenBLAS blas_thread_init: or set a smaller OPENBLAS_NUM_THREADS to fit into what you have available
AOpenBLAS blas_thread_init: RLIMIT_NPROC 40960 current, 40960 max
#Traceback (most recent call last):
* File "/app/app.py", line 2, in <module>
1 from data_analysis import DATimingDataClient
4 File "/app/data_analysis.py", line 8, in <module>
import pandas as pd
Z File "/usr/local/lib/python3.10/site-packages/pandas/init.py", line 14, in <module>
import(_dependency)
Z File "/usr/local/lib/python3.10/site-packages/numpy/init.py", line 114, in <module>
- from numpy.config import show_config
Z File "/usr/local/lib/python3.10/site-packages/numpy/config.py", line 4, in <module>
0 from numpy._core.multiarray_umath import (
File "/usr/local/lib/python3.10/site-packages/numpy/_core/init.py", line 23, in <module>
from . import multiarray
a File "/usr/local/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/usr/local/lib/python3.10/site-packages/numpy/_core/overrides.py", line 7, in <module>
0 from numpy._core._multiarray_umath import (
E File "<frozen importlib._bootstrap>", line 1022, in _find_and_load
KeyboardInterrupt
怎么解决 -
- 检查一下服务器上 ulimit 设置
- 检查 docker-compose.yml 你自己写的这个服务的 ulimits 设置
-
@chenpengchao 在 请教下开发python后端服务的一些问题 中说:
docker-compose.yml
现在服务运行起来了,怎样访问
* Serving Flask app 'app'
* Debug mode: on
�[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
& * Running on all addresses (0.0.0.0)
$ * Running on http://127.0.0.1:5000
& * Running on http://172.19.0.61:5000
[33mPress CTRL+C to quit[0m
* Restarting with stat
* Debugger is active!
* Debugger PIN: 131-320-878我按文档访问这个我的服务接口http://ip:31000/da/api/data没有返回
服务日志里显示收到了访问请求
R172.19.0.18 - - [19/Dec/2024 16:14:18] "[33mGET /da/api/data HTTP/1.1[0m" 404 -
R172.19.0.18 - - [19/Dec/2024 16:14:21] "[33mGET /da/api/data HTTP/1.1[0m" 404 -
R172.19.0.18 - - [19/Dec/2024 16:14:41] "[33mGET /da/api/data HTTP/1.1[0m" 404 -
R172.19.0.18 - - [19/Dec/2024 16:15:15] "[33mGET /da/api/data HTTP/1.1[0m" 404 -
R172.19.0.18 - - [19/Dec/2024 16:18:22] "[33mGET /da/api/data HTTP/1.1[0m" 404 -
J172.19.0.18 - - [19/Dec/2024 16:18:56] "[33mGET /da/ HTTP/1.1[0m" 404 -
I172.19.0.18 - - [19/Dec/2024 16:19:12] "[33mGET /da HTTP/1.1[0m" 404 -
R172.19.0.18 - - [19/Dec/2024 16:19:56] "[33mGET /da/api/data HTTP/1.1[0m" 404 -出现了404错误,服务本地测试是可以的
-
发一下 docker-compose.yml 和你自己开发服务的 service.yml 文件的内容
-
@chenpengchao
da:
container_name: da
image: 'da:latest'
labels:
- traefik.enable=true
- traefik.http.routers.da.entrypoints=web
- traefik.http.services.da.loadbalancer.server.port=31000
- traefik.http.routers.da.rule=PathPrefix(/da
)
- service.repo=da
- security-opt seccomp=unconfned
logging:
driver: json-file
options:
max-size: 100m
max-file: '1'
networks:
- backend
privileged: true
restart: always
ulimits:
nproc: 40960
nofile:
soft: 10240
hard: 30720
volumes:
- '/etc/localtime:/etc/localtime:ro'service.yml 文件的内容:
Name: da
Path: /da
Version: 1.0.0
Description: data_ana
GroupName: server
Service: Internal
Ports:
- Host: "31000" # 映射到宿主机的端口号, 如果不填写, 则会随机分配一个端口号
Container: "31000" # 服务监听的端口号, 即配置文件中 server.port 的值
Protocol: "" # 协议类型, 可选项有 TCP UDP, 如果不填写, 则默认为 TCP
- Host: "31000" # 映射到宿主机的端口号, 如果不填写, 则会随机分配一个端口号
-
- 你服务日志里监听的是 5000 端口,但是你 service.yml 中写的是 31000, 对不上
- 你的服务需要有一个统一的请求前缀 /da
- 不要用 31000 端口,这个是平台网关的端
- 如果你不通过平台网关访问服务的话,把 service.yml 中的 Service: Internal 改成 Service: External,而且 Container 填写的端口要和你实际监听的端口一致,但是实际访问端口要用 Host 的端口,或者平台随机生成的那个端口
-
@chenpengchao 通过平台网关访问服务是什么意思