Skip to content

Commit

Permalink
fix(utils): change logic of setup_env to provide better feeling (Megv…
Browse files Browse the repository at this point in the history
  • Loading branch information
FateScript authored Jul 22, 2021
1 parent ab01695 commit a026133
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions yolox/utils/setup_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.

import os
import resource
import subprocess

import cv2
Expand All @@ -28,13 +27,24 @@ def configure_module(ulimit_value=8192):
Configure pytorch module environment. setting of ulimit and cv2 will be set.
Args:
ulimit_value(int): default open file number on linux. Default value: 4096.
ulimit_value(int): default open file number on linux. Default value: 8192.
"""
# system setting
rlimit = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (ulimit_value, rlimit[1]))
try:
import resource
rlimit = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (ulimit_value, rlimit[1]))
except Exception:
# Exception might be raised in Windows OS or rlimit reaches max limit number.
# However, set rlimit value might not be necessary.
pass

# cv2
# multiprocess might be harmful on performance of torch dataloader
os.environ["OPENCV_OPENCL_RUNTIME"] = "disabled"
cv2.setNumThreads(0)
cv2.ocl.setUseOpenCL(False)
try:
cv2.setNumThreads(0)
cv2.ocl.setUseOpenCL(False)
except Exception:
# cv2 version mismatch might rasie exceptions.
pass

0 comments on commit a026133

Please sign in to comment.