Use open() instead of file() to open files
file() has been removed in Python3. Also, drop buffering=0 from the call - it doesn't work in text mode in Python3.
This commit is contained in:
parent
e039f07a96
commit
fba15bf0f6
3 changed files with 10 additions and 15 deletions
|
|
@ -41,9 +41,8 @@ def parse_def_affinity(fname):
|
|||
if os.getuid() != 0:
|
||||
return
|
||||
try:
|
||||
f = file(fname)
|
||||
line = f.readline()
|
||||
f.close()
|
||||
with open(fname, 'r') as f:
|
||||
line = f.readline()
|
||||
return bitmasklist(line)
|
||||
except IOError:
|
||||
return [ 0 ]
|
||||
|
|
|
|||
|
|
@ -40,12 +40,10 @@ def do_fork():
|
|||
sys.exit(0)
|
||||
|
||||
def close_fds():
|
||||
s_in = file('/dev/null', 'r')
|
||||
s_out = file('/dev/null', 'a+')
|
||||
s_err = file('/dev/null', 'a+', 0)
|
||||
os.dup2(s_in.fileno(), sys.stdin.fileno())
|
||||
os.dup2(s_out.fileno(), sys.stdout.fileno())
|
||||
os.dup2(s_err.fileno(), sys.stderr.fileno())
|
||||
f = open('/dev/null', 'w+')
|
||||
os.dup2(f.fileno(), sys.stdin.fileno())
|
||||
os.dup2(f.fileno(), sys.stdout.fileno())
|
||||
os.dup2(f.fileno(), sys.stderr.fileno())
|
||||
|
||||
def write_pidfile():
|
||||
with os.fdopen(os.open(PIDFILE, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o644), "w") as f:
|
||||
|
|
|
|||
|
|
@ -139,12 +139,10 @@ class Application(object):
|
|||
os.close(child_out_fd)
|
||||
raise TunedException("Cannot daemonize, second fork() failed.")
|
||||
|
||||
si = file("/dev/null", "r")
|
||||
so = file("/dev/null", "a+")
|
||||
se = file("/dev/null", "a+", 0)
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
fd = open("/dev/null", "w+")
|
||||
os.dup2(fd.fileno(), sys.stdin.fileno())
|
||||
os.dup2(fd.fileno(), sys.stdout.fileno())
|
||||
os.dup2(fd.fileno(), sys.stderr.fileno())
|
||||
|
||||
self.write_pid_file(pid_file)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue