Skip to Content
プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル
book

プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル

by Cristina Videira Lopes, 菊池 彰
June 2023
Intermediate to advanced content levelIntermediate to advanced
316 pages
4h 31m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル

29章アクター――スレッドActor

†1

[†1] 12章のレターボックススタイルに似ているが、モノが独立した実行スレッドを持つ。

制約

  • より大きな問題は、問題領域に対して意味のあるモノに分解される。
  • モノは、他のモノがメッセージを入れるためのキューを持つ。
  • モノは、データのカプセルであり、キュー経由でメッセージを受信する能力のみ公開する。
  • モノは、他とは独立した独自の実行スレッドを持つ。

プログラム

  1 #!/usr/bin/env python
  2
  3 import sys, re, operator, string
  4 from threading import Thread
  5 from queue import Queue
  6
  7 class ActiveWFObject(Thread):
  8     def __init__(self):
  9         super(ActiveWFObject, self).__init__()
 10         self.name = str(type(self))
 11         self.queue = Queue()
 12         self._stop_me = False
 13         self.start()
 14
 15     def run(self):
 16         while not self._stop_me:
 17             message = self.queue.get()
 18             self._dispatch(message)
 19 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SQLではじめるデータ分析 ―クエリで行う前処理、時系列解析、コホート分析、テキスト分析、異常検知

SQLではじめるデータ分析 ―クエリで行う前処理、時系列解析、コホート分析、テキスト分析、異常検知

Cathy Tanimura, 大橋 真也, 嶋田 健志, 木下 哲也
レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

David Scott Bernstein, 吉羽 龍太郎, 永瀬 美穂, 原田 騎郎, 有野 雅士
プログラミングRust 第2版

プログラミングRust 第2版

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall, 中田 秀基

Publisher Resources

ISBN: 9784814400225Other