Skip to content

Commit ae45e88

Browse files
committed
Lock Mailbox when used in a context manager
1 parent 47fd0fe commit ae45e88

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Doc/library/mailbox.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
7777
corrupting the entire mailbox.
7878

7979
The :class:`Mailbox` class supports the :keyword:`with` statement. When used
80-
like this, the Mailbox :meth:`close` method is called automatically when the
81-
:keyword:`with` statement exits.
80+
like this, the Mailbox get a lock when the :keyword:`with` statement enters and
81+
release it and :meth:`close` when the :keyword:`with` statement exits.
8282

8383
.. versionchanged:: 3.7
8484
Support for the :keyword:`with` statement was added.

Lib/mailbox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, path, factory=None, create=True):
3939
self._factory = factory
4040

4141
def __enter__(self):
42+
self.lock()
4243
return self
4344

4445
def __exit__(self, type, value, traceback):

0 commit comments

Comments
 (0)