V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
? Learn Python the Hard Way
Python Sites
? PyPI - Python Package Index
? http://diveintopython.org/toc/index.html
? Pocoo
值得关注的项目
? PyPy
? Celery
? Jinja2
? Read the Docs
? gevent
? pyenv
? virtualenv
? Stackless Python
? Beautiful Soup
? 结巴中文分词
? Green Unicorn
? Sentry
? Shovel
? Pyflakes
? pytest
Python 编程
? pep8 Checker
Styles
? PEP 8
? Google Python Style Guide
? Code Style from The Hitchhiker's Guide
chuncey
V2EX  ?  Python

Python 如何在类内多进程执行此类内的方法

  •  
  •   chuncey · 2018-04-17 18:05:48 +08:00 · 4958 次点击
    这是一个创建于 2213 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    有一个类似这样的类

    class Foo:
    
     def __init__(self):
        self.x = ''
        
     def func_1(self):
        self.x += 'f1'
        
     def func_2(self):
        self.x += 'f2'
        
     def process(self):
        self.func_1()
        self.func_2()
    

    有办法让类内的 func_1 和 func_2 同时执行吗(func_1 和 func_2 实例为爬虫程序)?

    7 条回复  ?  2018-04-18 10:06:36 +08:00
    orderc
        1
    orderc  
       2018-04-17 21:37:29 +08:00   ?? 1
    读这个标题舌头快打结了。。
    di94sh
        2
    di94sh  
       2018-04-17 22:17:23 +08:00   ?? 1
    orangeade
        3
    orangeade  
       2018-04-17 22:31:43 +08:00 via Android   ?? 1
    concurrent.futures.ProcessPoolExecutor
    或者 Asyncio ?
    di94sh
        4
    di94sh  
       2018-04-18 00:08:13 +08:00   ?? 1
    di94sh
        5
    di94sh  
       2018-04-18 00:12:50 +08:00
    使用多进程, 要改写父进程资源, 要使用一些进程间的通信手段, 共享内存在这里就挺合适的..不过要注意,多进程的同步,
    就是使用信号量,
    ZoomQuiet
        6
    ZoomQuiet  
       2018-04-18 08:28:14 +08:00 via iPhone
    redis
    shuizhengqi
        7
    shuizhengqi  
       2018-04-18 10:06:36 +08:00
    使用 celery 了解一下?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   999 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:28 · PVG 05:28 · LAX 14:28 · JFK 17:28
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com