From 8177f2b12ddf1d554c0c28a62188899e05b0882d Mon Sep 17 00:00:00 2001 From: Alexander Bersenev Date: Mon, 11 Jun 2018 17:33:57 +0500 Subject: [PATCH] automaticaly increase open file limit on start --- mtprotoproxy.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mtprotoproxy.py b/mtprotoproxy.py index 9a56cd8..d05df83 100755 --- a/mtprotoproxy.py +++ b/mtprotoproxy.py @@ -11,6 +11,7 @@ import random import binascii import sys + try: from Crypto.Cipher import AES from Crypto.Util import Counter @@ -48,6 +49,16 @@ except ImportError: return EncryptorAdapter(mode) +try: + import resource + soft_fd_limit, hard_fd_limit = resource.getrlimit(resource.RLIMIT_NOFILE) + resource.setrlimit(resource.RLIMIT_NOFILE, (hard_fd_limit, hard_fd_limit)) +except (ValueError, OSError): + print("Failed to increase the limit of opened files", flush=True, file=sys.stderr) +except ImportError: + pass + + import config PORT = getattr(config, "PORT") USERS = getattr(config, "USERS")