|
8 | 8 | :copyright: (c) 2013-present by Abhinav Singh and contributors.
|
9 | 9 | :license: BSD, see LICENSE for more details.
|
10 | 10 | """
|
11 |
| -import os |
12 | 11 | import sys
|
13 | 12 | import ssl
|
14 | 13 | import socket
|
|
20 | 19 | from types import TracebackType
|
21 | 20 | from typing import Optional, Dict, Any, List, Tuple, Type, Callable
|
22 | 21 |
|
| 22 | +from ._compat import IS_WINDOWS # noqa: WPS436 |
23 | 23 | from .constants import HTTP_1_1, COLON, WHITESPACE, CRLF, DEFAULT_TIMEOUT, DEFAULT_THREADLESS
|
24 | 24 |
|
25 |
| -if os.name != 'nt': |
| 25 | +if not IS_WINDOWS: |
26 | 26 | import resource
|
27 | 27 |
|
28 | 28 | logger = logging.getLogger(__name__)
|
@@ -272,14 +272,16 @@ def get_available_port() -> int:
|
272 | 272 |
|
273 | 273 | def set_open_file_limit(soft_limit: int) -> None:
|
274 | 274 | """Configure open file description soft limit on supported OS."""
|
275 |
| - if os.name != 'nt': # resource module not available on Windows OS |
276 |
| - curr_soft_limit, curr_hard_limit = resource.getrlimit( |
277 |
| - resource.RLIMIT_NOFILE, |
| 275 | + if IS_WINDOWS: # resource module not available on Windows OS |
| 276 | + return |
| 277 | + |
| 278 | + curr_soft_limit, curr_hard_limit = resource.getrlimit( |
| 279 | + resource.RLIMIT_NOFILE, |
| 280 | + ) |
| 281 | + if curr_soft_limit < soft_limit < curr_hard_limit: |
| 282 | + resource.setrlimit( |
| 283 | + resource.RLIMIT_NOFILE, (soft_limit, curr_hard_limit), |
| 284 | + ) |
| 285 | + logger.debug( |
| 286 | + 'Open file soft limit set to %d', soft_limit, |
278 | 287 | )
|
279 |
| - if curr_soft_limit < soft_limit < curr_hard_limit: |
280 |
| - resource.setrlimit( |
281 |
| - resource.RLIMIT_NOFILE, (soft_limit, curr_hard_limit), |
282 |
| - ) |
283 |
| - logger.debug( |
284 |
| - 'Open file soft limit set to %d', soft_limit, |
285 |
| - ) |
|
0 commit comments