Skip to content
Open
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: 3 additions & 15 deletions src/silx/app/view/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import traceback

from silx.app.utils import parseutils
from silx.utils.system_limit import increase_max_opened_files

_logger = logging.getLogger(__name__)
"""Module logger"""
Expand Down Expand Up @@ -102,20 +103,7 @@ def mainQt(options):
# Import most of the things here to be sure to use the right logging level
#

# Use max opened files hard limit as soft limit
try:
import resource
except ImportError:
_logger.debug("No resource module available")
else:
if hasattr(resource, "RLIMIT_NOFILE"):
try:
hard_nofile = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
resource.setrlimit(resource.RLIMIT_NOFILE, (hard_nofile, hard_nofile))
except (ValueError, OSError):
_logger.warning("Failed to retrieve and set the max opened files limit")
else:
_logger.debug("Set max opened files to %d", hard_nofile)
increase_max_opened_files()

# This needs to be done prior to load HDF5
hdf5_file_locking = "TRUE" if options.hdf5_file_locking else "FALSE"
Expand All @@ -131,10 +119,10 @@ def mainQt(options):
)

import silx
from silx.gui import qt

# Make sure matplotlib is configured
import silx.gui.utils.matplotlib # noqa
from silx.gui import qt
Comment on lines -134 to +125

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no reason to change import order in this PR


app = qt.QApplication.instance()
if app is None:
Expand Down
49 changes: 49 additions & 0 deletions src/silx/utils/system_limit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# /*##########################################################################
#
# Copyright (c) 2019 European Synchrotron Radiation Facility

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If set best to use the right date:

Suggested change
# Copyright (c) 2019 European Synchrotron Radiation Facility
# Copyright (c) 2026 European Synchrotron Radiation Facility

#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Utils function relative to system limit"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

well, i miss of imagination here


__authors__ = ["M. Ruyer"]
__license__ = "MIT"
__date__ = "05/06/2026"

import logging

_logger = logging.getLogger()


def increase_max_opened_files():

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

what do you think about that name ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

increase_opened_files_limit ? 🤷

"""Use max opened files hard limit as soft limit"""
try:
import resource
except ImportError:
_logger.debug("No resource module available")
else:
if hasattr(resource, "RLIMIT_NOFILE"):
Comment on lines +37 to +42

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about putting import at the top of the file to avoid lazy loading:

try:
    import resource
except ImportError:
    resource = None

and use this here:

Suggested change
try:
import resource
except ImportError:
_logger.debug("No resource module available")
else:
if hasattr(resource, "RLIMIT_NOFILE"):
if resource is None:
_logger.debug("No resource module available")
return
if hasattr(resource, "RLIMIT_NOFILE"):

try:
hard_nofile = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
resource.setrlimit(resource.RLIMIT_NOFILE, (hard_nofile, hard_nofile))
except (ValueError, OSError):
_logger.warning("Failed to retrieve and set the max opened files limit")
else:
_logger.debug("Set max opened files to %d", hard_nofile)
Loading