Results of 1 - 10 of about 11 for worker (0.009 sec.)
- ライブラリと拡張 FAQ 13478
- ライブラリと拡張 FAQ ライブラリ一般の質問 作業 X を行うためのモジュールやアプリケーションを探すにはどうしますか? ライブラリリファンレス から関係がありそうな標準ライブラリモジュールがあるかどうか調べてください。 (標準ライブラリに何があるかが
...なれば、 # それ以上の作業はないとして終了 (exit) する。 # (現実的には ワーカーは終了する (terminated) まで走り続ける) def worker (): print ( 'Running worker' ) time . sleep ( 0.1 ) while True : try : arg = q . get ( block = False ) except queue . Empt...y : print ( 'Worker' , threading . current_thread (), end = ' ' ) print ( 'queue empty' ) break else : print ( 'Worker' , threading . current_...キュー作成 q = queue . Queue () # 5 個のワーカーからなるプールを開始 for i in range ( 5 ): t = threading . Thread ( target = worker , name = 'worker %i ' % ( i + 1 )) t . start () # キューへの作業追加を開始 for i in range ( 50 ): q . put ( i ) # スレッド... - https://man.mtool.work/python/3.14/faq/library.html
- Logging クックブック 11042
- Logging クックブック Author : Vinay Sajip <vinay_sajip at red-dove dot com> このページは、過去に有用であるとされていた、logging に関連するいくつものレシピを含んでいます。チュートリアルやリファレンス情報へのリンクについては その他のリソース
...ん。 次の例はmain (初期) スレッドとそれ以外のスレッドからのロギングの例です: import logging import threading import time def worker ( arg ): while not arg [ 'stop' ]: logging . debug ( 'Hi from myfunc' ) time . sleep ( 0.5 ) def main (): logging . basicC...t = ' %(relativeCreated)6d %(threadName)s %(message)s ' ) info = { 'stop' : False } thread = threading . Thread ( target = worker , args = ( info ,)) thread . start () while True : try : logging . debug ( 'Hello from main' ) time . sleep ( 0.75 ) excep...ロセスの実行開始時に行う。 # Windows では fork の動作に頼れないため、 # 各プロセスが開始時にログ設定のコードを実行する。 def worker_configurer ( queue ): h = logging . handlers . QueueHandler ( queue ) # 必要なハンドラーはこの一つだけ root = logging . ge... - https://man.mtool.work/python/3.14/howto/logging-cookbook.html
- asyncio とフリースレッド Python 9673
- asyncio とフリースレッド Python asyncio uses an event loop as a scheduler to enable highly efficient concurrency by switching between tasks to allow non-blocking I/O operations. This results in better performance for I/O-bound use cases. It
...独立してタスクをスケジュールできます。 asyncio とスレッドを併用する例を示します。 import asyncio import threading async def worker ( name : str ) -> None : print ( f "Worker { name } starting" ) await asyncio . sleep ( 1 ) print ( f "Worker { name } don...e" ) def run_loop ( name : str ) -> None : asyncio . run ( worker ( name )) threads = [ threading . Thread ( target = run_loop , args = ( f "T { i } " ,)) for i in range ( 4 ) ] for t in t... - https://man.mtool.work/python/3.14/library/asyncio-threading.html
- キュー 8801
- キュー ソースコード: Lib/asyncio/queues.py asyncio キューは queue モジュールのクラス群と同じ形になるように設計されています。 asyncio キューはスレッドセーフではありませんが、それらは async/await コードから使われるために特別に設計されています
...って、並行処理を行う複数のタスクにワークロードを分散させることができます: import asyncio import random import time async def worker ( name , queue ): while True : # キューから作業項目を取り出す。 sleep_for = await queue . get () # sleep_for 秒スリープする...# キューを並行して処理する三つのワーカータスクを作成する。 tasks = [] for i in range ( 3 ): task = asyncio . create_task ( worker ( f 'worker- { i } ' , queue )) tasks . append ( task ) # キューの全項目の処理が完了するまで待つ。 started_at = time . mon...のキャンセルが完了するまで待つ。 await asyncio . gather ( * tasks , return_exceptions = True ) print ( '====' ) print ( f '3 workers slept in parallel for { total_slept_for : .2f } seconds' ) print ( f 'total expected sleep time: { total_sleep_time : .2f... - https://man.mtool.work/python/3.14/library/asyncio-queue.html
- concurrent.interpreters --- 同じプロセス内の複数のインタープリタ 8126
- concurrent.interpreters --- 同じプロセス内の複数のインタープリタ Added in version 3.14. ソースコード: Lib/concurrent/interpreters concurrent.interpreters モジュールは、低水準の _interpreters モジュールの上に、より高水準のインターフェースを構
...信する例。 from concurrent import interpreters interp = interpreters . create () queue = interpreters . create_queue () def worker ( queue ): queue . put ( 'spam!' ) t = interp . call_in_thread ( worker , queue ) print ( queue . get ()) t . join () 他の... - https://man.mtool.work/python/3.14/library/concurrent.interpreters.html
- queue --- 同期キュークラス 8126
- queue --- 同期キュークラス ソースコード: Lib/queue.py queue モジュールは、複数の生産者と消費者が使えるキューを実装しています。 複数のスレッド間で安全に情報を交換する必要があるスレッドプログラミングで特に役立ちます。 このモジュールの Queue ク
...れます。 タスクの完了を待つ キューに入れたタスクが完了するのを待つ例: import threading import queue q = queue . Queue () def worker (): while True : item = q . get () print ( f 'Working on { item } ' ) print ( f 'Finished { item } ' ) q . task_done () #...ワーカースレッドを起動する。 threading . Thread ( target = worker , daemon = True ) . start () # ワーカーに 30 件のタスクを送る。 for item in range ( 30 ): q . put ( item ) # すべてのタスク... - https://man.mtool.work/python/3.14/library/queue.html
- concurrent.futures --- 並列タスク実行 7930
- concurrent.futures --- 並列タスク実行 Added in version 3.2. ソースコード: Lib/concurrent/futures/thread.py 、 Lib/concurrent/futures/process.py および Lib/concurrent/futures/interpreter.py concurrent.futures モジュールは、呼び出し可能オブジ
...ようにスケジュールし、呼び出し可能オブジェクトの実行を表現する Future オブジェクトを返します。 with ThreadPoolExecutor ( max_workers = 1 ) as executor : future = executor . submit ( pow , 323 , 1235 ) print ( future . result ()) map ( fn , * iterables ,...wait を True にして Executor.shutdown() を呼び出した場合と同様に待機します)。 import shutil with ThreadPoolExecutor ( max_workers = 4 ) as e : e . submit ( shutil . copy , 'src1.txt' , 'dest1.txt' ) e . submit ( shutil . copy , 'src2.txt' , 'dest2.txt...time . sleep ( 5 ) print ( a . result ()) # a は b を待っているため完了しない return 6 executor = ThreadPoolExecutor ( max_workers = 2 ) a = executor . submit ( wait_on_b ) b = executor . submit ( wait_on_a ) 以下でも同様です: def wait_on_future (): f... - https://man.mtool.work/python/3.14/library/concurrent.futures.html
- A Conceptual Overview of asyncio 7735
- A Conceptual Overview of asyncio この HOWTO では、 asyncio の基本的な仕組みをしっかり理解できるように説明します。 推奨される書き方がどのように動き、なぜ推奨されるのかを理解する助けになるでしょう。 asyncio の主要な概念について、疑問を持ってい
...wer is explicitly granted to it, but a lot of its ability to get things done comes from the respect and cooperation of its worker bees. In more technical terms, the event loop contains a collection of jobs to be run. Some jobs are added directly by you... - https://man.mtool.work/python/3.14/howto/a-conceptual-overview-of-asyncio.html
- multiprocessing --- プロセスベースの並列処理 7628
- multiprocessing --- プロセスベースの並列処理 ソースコード: Lib/multiprocessing/ 利用可能な環境 : not Android, not iOS, not WASI. このモジュールは モバイルプラットフォーム と WebAssemblyプラットフォーム をサポートしません。 はじめに multipro
...rt Pool >>> p = Pool ( 5 ) >>> def f ( x ): ... return x * x ... >>> with p : ... p . map ( f , [ 1 , 2 , 3 ]) Process PoolWorker-1: Process PoolWorker-2: Process PoolWorker-3: Traceback (most recent call last): Traceback (most recent call last): Trace...クセスします: >>> from multiprocessing import Process , Queue >>> from multiprocessing.managers import BaseManager >>> class Worker ( Process ): ... def __init__ ( self , q ): ... self . q = q ... super () . __init__ () ... def run ( self ): ... self . q.... put ( 'local hello' ) ... >>> queue = Queue () >>> w = Worker ( queue ) >>> w . start () >>> class QueueManager ( BaseManager ): pass ... >>> QueueManager . register ( 'get_queue' , ca... - https://man.mtool.work/python/3.14/library/multiprocessing.html
- 変更履歴 7628
- 変更履歴 次の Python バージョン リリース日: XXXX-XX-XX セキュリティ gh-160499 : Fix unbounded memory growth in asyncio TLS connections when a peer stops reading but keeps sending records that make OpenSSL generate its own replies (such as T
...ed instead of overflowing the C stack. ライブラリ gh-160549 : Fix a crash when a compression.zstd.ZstdCompressor that uses worker threads and a ZstdDict is deallocated, or the interpreter exits, while data passed to compress() is still being compressed.... gh-160535 : Fix a crash in compression.zstd when the garbage collector frees a ZstdCompressor that uses worker threads together with its ZstdDict before the compression of already submitted data has finished. gh-160520 : Fix asyncio... - https://man.mtool.work/python/3.14/whatsnew/changelog.html