'import resource' only where its used, Windows does not have it

This commit is contained in:
Hans-Christoph Steiner 2021-06-18 10:24:44 +02:00
parent 36849b2fba
commit 1300771bad
No known key found for this signature in database
GPG key ID: 3E177817BA1B9BFA

View file

@ -23,7 +23,6 @@ import glob
import subprocess import subprocess
import posixpath import posixpath
import re import re
import resource
import sys import sys
import tarfile import tarfile
import threading import threading
@ -1026,17 +1025,22 @@ def main():
raise FDroidException("No apps to process.") raise FDroidException("No apps to process.")
# make sure enough open files are allowed to process everything # make sure enough open files are allowed to process everything
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) try:
if len(apps) > soft: import resource # not available on Windows
try:
soft = len(apps) * 2 soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft > hard: if len(apps) > soft:
soft = hard try:
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard)) soft = len(apps) * 2
logging.debug(_('Set open file limit to {integer}') if soft > hard:
.format(integer=soft)) soft = hard
except (OSError, ValueError) as e: resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))
logging.warning(_('Setting open file limit failed: ') + str(e)) logging.debug(_('Set open file limit to {integer}')
.format(integer=soft))
except (OSError, ValueError) as e:
logging.warning(_('Setting open file limit failed: ') + str(e))
except ImportError:
pass
if options.latest: if options.latest:
for app in apps.values(): for app in apps.values():