V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Apr 17, 2018 · 5886 views
    This topic created in 2941 days ago, the information mentioned may be changed or developed.

    有一个类似这样的类

    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 replies    2018-04-18 10:06:36 +08:00
    orderc
        1
    orderc  
       Apr 17, 2018   ❤️ 1
    读这个标题舌头快打结了。。
    orangeade
        3
    orangeade  
       Apr 17, 2018 via Android   ❤️ 1
    concurrent.futures.ProcessPoolExecutor
    或者 Asyncio ?
    di94sh
        4
    di94sh  
       Apr 18, 2018   ❤️ 1
    di94sh
        5
    di94sh  
       Apr 18, 2018
    使用多进程, 要改写父进程资源, 要使用一些进程间的通信手段, 共享内存在这里就挺合适的..不过要注意,多进程的同步,
    就是使用信号量,
    ZoomQuiet
        6
    ZoomQuiet  
       Apr 18, 2018 via iPhone
    redis
    shuizhengqi
        7
    shuizhengqi  
       Apr 18, 2018
    使用 celery 了解一下?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4937 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 09:56 · PVG 17:56 · LAX 02:56 · JFK 05:56
    ♥ Do have faith in what you're doing.