Python Concurrency

发布于 2017-11-07 13:55:05

  • 多进程
    • fork()
      • getpid()
      • getppid()
    • multiprocessing
      • Process
        • start()
        • join()
      • Pool
        • map()
        • imap_unordered()
        • apply_async()
        • close()
        • join()
      • (Exchange objects)
        • Queue
          • put()
          • get()
          • empty()
          • full()
          • qsize()
          • close()
          • join_thread()
          • cancel_join_thread()
          • Queues are thread and process safe.
          • doc of methods
        • Pipes
      • (Synchronization between processes)
        • Lock
      • (Sharing state between processes)
        • Value, Array
          • process and thread-safe
        • Manager
          • list, dict, Namespace, Lock, RLock, Semaphore, BoundedSemaphore, Condition, Event, Queue, Value and Array
      • managers
        • common
          • register()
        • server
          • start()
          • shutdown()
        • client
          • connect()
      • (miscellaneous)
        • active_children()
        • cpu_count()
        • current_process()
      • get_logger(), log_to_stderr()
      • Programming guidelines
    • 多个Python进程有各自独立的GIL锁,互不影响
  • 多线程
    • thread
    • threading
      • Thread
        • start()
        • join()
      • current_thread()
      • Lock
        • acquire()
        • release()
      • ThreadLocal
    • 多线程编程,模型复杂,容易发生冲突,必须用锁加以隔离,同时,又要小心死锁的发生
  • 架构
    • Master-Worker
    • 进程
    • 线程
      • 开销小
      • 稳定性低
      • 不能利用多核
      • 异步IO
    • 计算密集 vs IO密集
comments powered by Disqus