mori– Author –
-
Python樹林
【Python】Basics of Implementing Asynchronous Processing with async/await
Overview This article explains the basic way to write "Asynchronous Processing" using Python's asyncio module. Traditional synchronous processing (using time.sleep) stops the entire program until a task is finished. By using asynchronous... -
Python樹林
【Python】async/awaitで非同期処理を実装する基本
概要 Pythonの asyncio モジュールを使用した「非同期処理(Asynchronous Processing)」の基本的な書き方を解説します。 従来の同期処理(time.sleep 等)は処理が終わるまでその場でプログラム全体が止まってしまいますが、非同期処理(await asyncio.sl... -
Python樹林
【Python】Using Timeouts with Thread-Safe Queues
Overview By default, the put() and get() methods of queue.Queue wait indefinitely (block) until the operation is completed. By specifying the timeout argument, you can raise an exception (Full or Empty) if the operation does not complete... -
Python樹林
【Python】スレッドセーフなキューでタイムアウトを使用する
概要 queue.Queue の put() と get() は、デフォルトでは処理が完了するまで「無限に待機(ブロック)」します。 timeout 引数を指定することで、一定時間待っても処理が完了しない場合に例外(Full または Empty)を発生させ、プログラムがフリーズするの... -
Python樹林
【Python】Safely Passing Data with Thread-Safe Queues
Overview The queue module in Python provides a mechanism to safely exchange (communicate) data between threads in multi-threaded programming. If you operate standard data structures like a list across multiple threads simultaneously, dat... -
Python樹林
【Python】スレッドセーフなキューでデータを安全に受け渡す
概要 Pythonの queue モジュールは、マルチスレッドプログラミングにおいて、スレッド間でデータを安全にやり取り(通信)するための仕組みを提供します。 list などの通常のデータ構造を複数のスレッドで同時に操作するとデータが破損する恐れがあります... -
Python樹林
【Python】Thread Exclusive Control: Preventing Contention with threading.Lock
Overview In multithreading, when multiple threads try to modify the same variable or resource (files, databases, global variables, etc.) at the same time, data can lose consistency. This is called a "Race Condition." To prevent this, we ... -
Python樹林
【Python】スレッドの排他制御:threading.Lockで競合を防ぐ
概要 マルチスレッド処理において、複数のスレッドが同じ変数やリソース(ファイル、データベース、グローバル変数など)を同時に書き換えようとすると、データが整合性を失う「競合状態(Race Condition)」が発生します。 これを防ぐために threading.Lo... -
Python樹林
【Python】Creating Custom Thread Classes by Inheriting the Thread Class
Overview This article explains how to implement multithreading by inheriting (subclassing) the Thread class in the Python threading module. Compared to simply passing a function to the target argument, this approach is effective when you... -
Python樹林
【Python】Threadクラスを継承して独自の処理スレッドを作る
概要 Pythonの threading モジュールでマルチスレッド処理を実装する際、Thread クラスを継承(サブクラス化)する方法を解説します。 単に関数を target に指定する方法と比較して、スレッド自体に独自のデータ(状態)を持たせたり、複雑なロジックをク... -
Python樹林
【Python】Checking if a Thread is Running or Finished with is_alive()
Overview This article explains how to check whether a thread created with Python's threading module is currently running (alive) or has already finished its task. By using the is_alive() method, you can control your program to perform ot... -
Python樹林
【Python】スレッドが実行中か確認する:is_aliveメソッドの使い方
概要 Pythonの threading モジュールで作成したスレッドが、現在動作中(生存中)なのか、それとも既に処理を終えているのかを確認する方法を解説します。 is_alive() メソッドを使用することで、スレッドの完了を待ちながら別の処理(進捗表示やログ出力... -
Python樹林
【Python】Implementing Concurrency (Multithreading) with the threading Module
Overview This article explains how to implement multithreading to run multiple processes concurrently using Python's standard threading module. This is a basic technique for efficiently handling tasks that involve waiting times (I/O-boun... -
Python樹林
【Python】threadingモジュールで並行処理(マルチスレッド)を実装する
概要 Python標準の threading モジュールを使用して、複数の処理を並行して実行するマルチスレッドの実装方法を解説します。 API通信やファイルの読み書きなど、待ち時間(I/O待ち)が発生するタスクを効率よく処理するための基礎技術です。引数の渡し方(... -
Python樹林
【Python】Concurrency Basics: Differences and Use Cases for Multithreading, Multiprocessing, and Async/await
Overview This article explains three approaches to making your Python code faster and more efficient: Multithreading, Multiprocessing, and Asynchronous programming (async/await). While all three are technologies for "handling multiple ta... -
Python樹林
【Python】並行処理の基本:マルチスレッド・マルチプロセス・async/awaitの違いと使い分け
概要 Pythonで処理を高速化・効率化するための3つのアプローチ(マルチスレッド、マルチプロセス、非同期処理)について解説します。 これらは「複数のタスクを同時にこなす」ための技術ですが、得意な場面が全く異なります。それぞれの仕組みを理解し、適... -
Python樹林
【Python】Saving Attachments from EmailMessage Objects
Overview This article explains how to extract and save attachments from an EmailMessage object (retrieved via Python's email module) to a local disk. We will cover handling binary files like images and PDFs, as well as correctly re-encod... -
Python樹林
【Python】EmailMessageオブジェクトから添付ファイルを取り出して保存する
概要 Pythonの email モジュールを使用して、受信したメール(EmailMessage オブジェクト)から添付ファイルを抽出し、ローカルディスクに保存する方法を解説します。 画像やPDFなどのバイナリファイルだけでなく、テキスト形式の添付ファイルが自動デコー... -
Python樹林
【Python】Extracting Subject, Sender, and Body from EmailMessage Objects
Overview This article explains how to properly extract header information (Subject, From, To) and the message body (Plain Text or HTML) from an EmailMessage object created by Python's email module. We will introduce a modern method using... -
Python樹林
【Python】EmailMessageオブジェクトから件名・宛先・本文を抽出する
概要 Pythonの email モジュールで生成された EmailMessage オブジェクトから、メールの件名、送信元、宛先などのヘッダー情報と、本文(プレーンテキストやHTML)を適切に取り出す方法を解説します。 特にマルチパート形式(HTMLとテキストが混在するメー... -
Python樹林
【Python】Receiving and Parsing Emails from IMAP Servers
Overview This article explains how to receive emails from an IMAP server using Python's standard imaplib library. We will cover the entire process, including connecting to the server and using the email module to parse received data into... -
Python樹林
【Python】imaplibでメールを受信・取得する:IMAP4_SSLとemailモジュールの連携
概要 Python標準ライブラリの imaplib を使用して、IMAPサーバーからメールを受信・取得する方法を解説します。 単にデータを受信するだけでなく、email モジュールと連携して、件名や本文、送信元アドレスを扱いやすいオブジェクト(EmailMessage型)とし... -
Python樹林
【Python】How to Send Emails with Attachments (Automatic MIME Type Detection)
Overview This article explains how to create and send emails with attachments such as PDFs or images using the standard Python library email.message. We will show a versatile implementation that uses the mimetypes module to automatically... -
Python樹林
【Python】メールにファイルを添付して送信する方法(MIMEタイプ自動判定)
概要 Python標準ライブラリ email.message を使用して、PDFや画像などのファイルを添付したメールを作成・送信する方法を解説します。 添付ファイルのデータ形式(MIMEタイプ)を mimetypes モジュールで自動判定させることで、様々な種類のファイルを汎用... -
Python樹林
【Python】Sending Emails with smtplib and EmailMessage: Supporting HTML Emails
Overview This article explains how to send emails using Python's standard libraries: smtplib and email.message. We will use the modern EmailMessage class, which is recommended for Python 3.6 and later, instead of the older and more compl... -
Python樹林
【Python】smtplibとEmailMessageでメールを送信する:HTMLメール対応
概要 Python標準ライブラリの smtplib と email.message モジュールを使用して、メールを送信する方法を解説します。 従来の複雑な MIMEText などを使用せず、Python 3.6以降で推奨されるモダンで扱いやすい EmailMessage クラスを使用した実装を紹介しま... -
Python樹林
【Python】Correctly Waiting for Element Display and Loading in Selenium
Overview Modern websites using SPA (Single Page Applications) or Ajax often do not show all elements immediately after a page opens. Elements may appear with a slight delay. To operate these elements without errors in Selenium, "wait pro... -
Python樹林
【Python】Seleniumで要素の表示・読み込み完了を正しく待機する
概要 最近のWebサイト(SPAやAjax使用サイト)では、ページを開いた直後にはまだ要素が存在せず、少し遅れて表示されることがよくあります。 Seleniumでエラーを出さずにこれらを操作するためには、要素が出現するまで適切にプログラムを一時停止させる「... -
Python樹林
【Python】Saving Web Page Screenshots with Selenium
Overview This article explains how to use Selenium to save the currently displayed web page as an image file (PNG format). This feature is essential for recording evidence during automated testing or collecting screen data while crawling... -
Python樹林
【Python】SeleniumでWebページのスクリーンショットを保存する
概要 Seleniumを使用して、現在ブラウザに表示されているWebページのスクリーンショットを画像ファイル(PNG形式)として保存する方法を解説します。 テスト自動化におけるエビデンス(証拠画像)の記録や、Web巡回による画面収集などに必須の機能です。 ...