Skip to content
Merged
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
14 changes: 12 additions & 2 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common import utils

try:
from subprocess import DEVNULL
_HAS_NATIVE_DEVNULL = True
except ImportError:
DEVNULL = -3
_HAS_NATIVE_DEVNULL = False


class Service(object):

def __init__(self, executable, port=0, log_file=PIPE, env=None, start_error_message=""):
def __init__(self, executable, port=0, log_file=DEVNULL, env=None, start_error_message=""):
self.path = executable

self.port = port
if self.port == 0:
self.port = utils.free_port()

if not _HAS_NATIVE_DEVNULL and log_file == DEVNULL:
log_file = open(os.devnull, 'wb')

self.start_error_message = start_error_message
self.log_file = log_file
self.env = env or os.environ
Expand Down Expand Up @@ -126,7 +136,7 @@ def stop(self):
"""
Stops the service.
"""
if self.log_file != PIPE:
if self.log_file != PIPE and not (self.log_file == DEVNULL and _HAS_NATIVE_DEVNULL):
try:
self.log_file.close()
except Exception:
Expand Down