rainit2006 / Python-room

my python room
0 stars 0 forks source link

总结2020 #23

Open rainit2006 opened 3 years ago

rainit2006 commented 3 years ago

Python 调用 so 库文件

1 将C++文件编译成so文件

g++ -fPIC -shared -o ctypes ctypes.cpp

2 Python代码调用

from  ctypes import *
lib=CDLL("ctypes")
lib.CtypesDemo("公众号:Python学习开发",4,5)
rainit2006 commented 3 years ago

Supervisor: Process monitoring tool

https://zhuanlan.zhihu.com/p/63340417、 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。它是通过fork/exec的方式把这些被管理的进程当作supervisor的子进程来启动,这样只要在supervisor的配置文件中,把要管理的进程的可执行文件的路径写进去即可。

supervisor其配置文件的目录位于: /etc/supervisord.conf (主配置文件,下面会详细介绍) /etc/supervisor.d/ (默认子进程配置文件,也就是需要我们根据程序配置的地方)

rainit2006 commented 3 years ago

Web 框架

FastAPI

自带 Swagger 作为 API 文档 https://zhuanlan.zhihu.com/p/157999491

rainit2006 commented 3 years ago

python 里调用php脚本

# init command
        cmd = 'export API_SITE=http://{}; php /mnt/api-engine/service/root/script/xxxxxx.php  callAPI_1 {} {}'

proc = await asyncio.create_subprocess_shell(
            cmd . format(self._config['host'], first_image_path.name, second_image_path.name),
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE)

# get stdout 
        stdout, stderr = await proc.communicate()

# check stdout 
        if proc.returncode != 0:
            return None