Write Elegant Concurrent Code in Python

  • R0
  • 第 3 天,11:15‑12:00
  • 中文演講/英文投影片
  • 最佳實踐與慣例
  • 中階

Writing concurrent program is hard; maintaining concurrent program even is a nightmare. Actually, a pattern which helps us to write good concurrent code is available, that is, using “channels” to communicate. This talk will share the channel concept with common libraries, like threading and multiprocessing, to make concurrent code elegant.

撰寫並行程式(concurrent program),例如多執行緒程式等,通常是困難的,而維護並行程式又是一場惡夢。其實有個方法可以寫出好的並行程式,只要使用 channel 做為溝通基礎,就可以寫出好維護的並行程式。這場演講會介紹如何在常見的函數庫,例如 threading、multiprocessing 等,中引入 channel 的概念,讓並行程式變得優雅。

演講詳細內容

The concept of channel is from the CSP (communicating sequential processes). It's a famous mathematical theory of concurrent systems [1]. The Go (golang) uses it as its fundamental concurrency design [2]. The programmers can design simpler and more maintainable concurrent code with this theory [3]. Although the CSP is not a part of Python, but we still can use common libraries to realize CSP and write better concurrent code. This talk will introduce how to use common Python libraries to realize CSP. Channel 這個概念是來自於 CSP(communicating sequential processes),其是一個著名的並行系統(concurrent system)的數學理論 [1],並獲得 Go(golang)採用作為其並行設計的基礎 [2],使用此理論可以設計出較為簡單、好維護的並行程式 [3]。 雖然 Python 並沒有將 CSP 設計成語言的一部份,但我們仍可以利用常見函數庫內的工具實現 CSP,寫出更好維護的並行程式。這場演講會介紹利用 Python 常見函數庫實現 CSP 的方法。 [1]: https://en.wikipedia.org/wiki/Communicating_sequential_processes [2]: https://golang.org/doc/effective_go.html#concurrency [3]: https://golang.org/doc/faq#csp

投影片連結

講者介紹

Mosky Liu

Mosky 是個熱愛 open source 精神的 Python 工程師,也是 Pinkoi 的 Python Charmer,工作時和同事一起打造能夠買到獨特禮物的設計品購物平台。

自從寫下人生第一支程式後,就難以忘懷以敘述為磚、邏輯為泥,堆砌出腦中藍圖的成就感,也熱愛分享自己所學,業餘時是 Python 課程講師,偶爾講點資料科學。也是數場國內外研討會的講者,包含臺灣的 PyCon、COSCUP、TEDxNTUST,以及在日本、新加坡、香港、韓國、馬來西亞等地的 PyCon。More: mosky.tw 。