V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  ytymf  ›  全部回复第 4 页 / 共 4 页
回复总数  72
1  2  3  4  
@hanssx 很难说 celery worker 本身的实现里面没有线程,而且大概率是有线程的。你可以简单试试改下进程启动方法为 spawn,如果问题解决那就是这个问题。
@hanssx 看 fork 的介绍,Note that safely forking a multithreaded process is problematic. 我的经验是,后果就是 fork 出的子进程会成为僵尸进程
@hanssx 不,就是确保父进程是单线程的,也就是说你要 fork 的那个进程里不能有多个线程。可以了解一下 fork safe 这个概念,fork 出来的子进程并不会继承父进程的所有线程,会造成一些问题。
为了解决这个问题,multiprocessing 给出了 spwan 跟 forkserver 两个启动子进程的方式,这里摘抄一点官方文档:

Depending on the platform, multiprocessing supports three ways to start a process. These start methods are

spawn
The parent process starts a fresh python interpreter process. The child process will only inherit those resources necessary to run the process objects run() method. In particular, unnecessary file descriptors and handles from the parent process will not be inherited. Starting a process using this method is rather slow compared to using fork or forkserver.

Available on Unix and Windows. The default on Windows and macOS.

fork
The parent process uses os.fork() to fork the Python interpreter. The child process, when it begins, is effectively identical to the parent process. All resources of the parent are inherited by the child process. Note that safely forking a multithreaded process is problematic.

Available on Unix only. The default on Unix.

forkserver
When the program starts and selects the forkserver start method, a server process is started. From then on, whenever a new process is needed, the parent process connects to the server and requests that it fork a new process. The fork server process is single threaded so it is safe for it to use os.fork(). No unnecessary resources are inherited.
multiprocessing 一定要确保父进程是单线程的,如果不能确保,可以尝试一下启动方式为 spawn 或者 forkserver 启动进程。
2019-10-28 10:20:13 +08:00
回复了 onice 创建的主题 程序员 纠结技术选型,到底用 django 还是 springboot
@cmdOptionKana django 自带一个 admin 页面,可以直接映射数据库表,可以做简单的增删查改
任务队列是正道,如果觉得 celery 麻烦,可以试试轻量化的 Huey,redis 默认配置就能跑
2019-09-05 14:38:43 +08:00
回复了 flyme6 创建的主题 问与答 你们平时,用什么图形化管理 MYSQL 数据库的工具
@kasper4649 还有我
2019-08-28 11:27:54 +08:00
回复了 XuanYuan 创建的主题 Apple 不要相信任何来路不明的 AirPods
@LINGJUN 现在的版本可以不显示那个蓝牙标了。。。。唯一的区别就是不能自定义操作。
@Raul7 这个不仅仅是简单不简单的问题。你的 flask 代码并不是一个单例,webserver 会根据访问情况启动多个 flask 实例。如果你是在业务代码中启动 apscheduler 的话,也会启动多个 apscheduler 的实例,定时任务就都乱了。 我疑似你的获取不到上下文,很可能就不是在一个进程中。
感觉楼主的路走偏了,这种异步任务应该用任务队列来做,不应该用 apscheduler 吧。可以考虑一下用 celery
2019-07-04 13:13:33 +08:00
回复了 LosLord 创建的主题 职场话题 收到 Offer 让第二天报到是什么情况
赞楼上,报个平安
2019-07-02 11:29:41 +08:00
回复了 noli 创建的主题 Python [可能引战] 用过 Python 也没法理解为什么 Python 是个好语言
你说的第一条就已经很重要了,对于编程水平不怎么好的人来说,python 上来能实现很多功能
1  2  3  4  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2484 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 36ms · UTC 11:43 · PVG 19:43 · LAX 04:43 · JFK 07:43
Developed with CodeLauncher
♥ Do have faith in what you're doing.