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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
MOLER_DEBUG_THREADS: True
PYTHON_COVERAGE: '3.14'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.os }} ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down Expand Up @@ -95,11 +95,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.14]
python-version: ["3.14"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.os }} ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

17 changes: 8 additions & 9 deletions moler/asyncio_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@


current_process = psutil.Process()
if platform.system() == 'Linux':

# Check if RLIMIT_NOFILE is available in your psutil
# noinspection PyUnresolvedReferences
(max_open_files_limit_soft, max_open_files_limit_hard) = current_process.rlimit(psutil.RLIMIT_NOFILE)
else:
if platform.system() == 'Windows':
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmaxstdio?view=vs-2019
(max_open_files_limit_soft, max_open_files_limit_hard) = (510, 512) # TODO: any way on Win?
else:
# Unix (Linux, Darwin, BSD, ...): read the real RLIMIT_NOFILE via stdlib resource module.
import resource
(max_open_files_limit_soft, max_open_files_limit_hard) = resource.getrlimit(resource.RLIMIT_NOFILE)


def system_resources_usage():
if platform.system() == 'Linux':
curr_fds_open = current_process.num_fds()
else:
if platform.system() == 'Windows':
ofiles = current_process.open_files()
osockets = current_process.connections(kind="all")
curr_fds_open = len(ofiles) + len(osockets) # TODO: any better way on Win?
else:
curr_fds_open = current_process.num_fds()
curr_threads_nb = threading.active_count()
return curr_fds_open, curr_threads_nb

Expand Down
23 changes: 23 additions & 0 deletions moler/config/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ def change_logging_suffix(suffix=None, logger_name=None):
)


def _is_foreign_file_handler(handler):
"""
Tell whether a FileHandler was not created by Moler and must not be reopened.

Other libraries (e.g. pytest, since its 9.0 logging change) attach their own
FileHandlers to Moler's non-propagating loggers. pytest's default handler points
to os.devnull ('/dev/null'); reopening it with a Moler suffix/path would yield an
unwritable path like '/dev/null.suffix' and raise PermissionError. Such handlers
are owned by the other library, so Moler should leave them untouched.

:param handler: logging.FileHandler to inspect.
:return: True if the handler points to os.devnull and should be skipped.
"""
try:
return os.path.abspath(handler.baseFilename) == os.path.abspath(os.devnull)
except (AttributeError, TypeError):
return False


def _reopen_all_logfiles_with_new_suffix(logger_suffixes, new_suffix, logger_name):
"""
Reopen all log files with new suffix.
Expand All @@ -308,6 +327,8 @@ def _reopen_all_logfiles_with_new_suffix(logger_suffixes, new_suffix, logger_nam
written_to_log = False
for handler in logger_handlers:
if isinstance(handler, logging.FileHandler):
if _is_foreign_file_handler(handler):
continue
new_log_full_path = _get_new_filepath_with_suffix(
old_path=handler.baseFilename,
old_suffix=old_suffix,
Expand Down Expand Up @@ -367,6 +388,8 @@ def _reopen_all_logfiles_in_new_path(old_logging_path, new_logging_path):

for handler in logger_handlers:
if isinstance(handler, logging.FileHandler):
if _is_foreign_file_handler(handler):
continue
handler.close()
handler.baseFilename = handler.baseFilename.replace(
old_logging_path, new_logging_path
Expand Down
2 changes: 0 additions & 2 deletions py3pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
[pytest]
python_files = test_*.py py3test_*.py # testfiles running only under python3 start with py3test_
mccabe-complexity =
*.py 10
6 changes: 1 addition & 5 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
-r base.txt
pycodestyle
coveralls
coverage
pytest
pytest-mccabe
pytest-random
mock
pytest-cov
pytest-asyncio
flake8
pydocstyle
pylint
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[tool:pytest]
mccabe-complexity =
*.py 10

[pycodestyle]
count = True
ignore = E501
Expand Down
8 changes: 5 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@


current_process = psutil.Process()
if platform.system() == 'Linux':
(max_open_files_limit_soft, max_open_files_limit_hard) = current_process.rlimit(psutil.RLIMIT_NOFILE)
else:
if platform.system() == 'Windows':
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmaxstdio?view=vs-2019
(max_open_files_limit_soft, max_open_files_limit_hard) = (510, 512) # TODO: any way on Win?
else:
# Unix (Linux, Darwin, BSD, ...): read the real RLIMIT_NOFILE via stdlib resource module.
import resource
(max_open_files_limit_soft, max_open_files_limit_hard) = resource.getrlimit(resource.RLIMIT_NOFILE)


def system_resources_usage():
Expand Down
Loading