Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,24 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if sys.platform != 'darwin' or os.environ.get('B2_TEST_DISABLE_TQDM_CLOSER'):
if (
sys.platform != 'darwin'
or sys.version_info < (3, 11)
or os.environ.get('B2_TEST_DISABLE_TQDM_CLOSER')
):
return

# Tqdm sempaphore leaks do not seem to happen in MacOS 15.7.2,
# so we can skip the workaround starting from this version
try:
macos_version = platform.mac_ver()[0]
version_tuple = tuple(int(v) for v in macos_version.split('.'))
except (KeyError, ValueError):
pass
else:
if version_tuple and version_tuple >= (15, 7, 2):
return

try:
from multiprocessing.synchronize import SemLock

Expand Down
1 change: 1 addition & 0 deletions changelog.d/+tqdm-closer-new-macos.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable Tqdm semaphore leak workaround for MacOS >= 15.7.2, as apparently it is no longer an issue in newer versions.
20 changes: 2 additions & 18 deletions test/integration/test_tqdm_closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
import re
import sys

import pytest


@pytest.mark.skipif(
(sys.platform != 'darwin') or ((sys.version_info.major, sys.version_info.minor) < (3, 11)),
reason='Tqdm closing error only occurs on OSX and python 3.11 or newer',
(sys.platform != 'darwin'),
reason='Tqdm closing error only occurs on OSX',
)
def test_tqdm_closer(b2_tool, bucket, file_name):
# test that stderr doesn't contain any warning, in particular warnings about multiprocessing resource tracker
Expand All @@ -27,18 +26,3 @@ def test_tqdm_closer(b2_tool, bucket, file_name):
f'b2://{bucket.name}/{file_name}',
]
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of the test does not make much sense now that the newer MacOS image is used in the CI

# test that disabling _TqdmCloser does produce a resource tracker warning. Should the following check ever fail,
# that would mean that either Tqdm or python fixed the issue and _TqdmCloser can be disabled for fixed versions
b2_tool.should_succeed(
[
'file',
'cat',
f'b2://{bucket.name}/{file_name}',
],
additional_env={'B2_TEST_DISABLE_TQDM_CLOSER': '1'},
expected_stderr_pattern=re.compile(
r'UserWarning: resource_tracker: There appear to be \d+ leaked semaphore'
r' objects to clean up at shutdown'
),
)