Mercurial > templog
comparison py/utils.py @ 230:185621f47040
run 2to3
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 10 Apr 2015 23:59:16 +0800 |
parents | d686b111dab4 |
children | 0a1b642e3086 |
comparison
equal
deleted
inserted
replaced
229:99255c501e02 | 230:185621f47040 |
---|---|
58 if d is not None: | 58 if d is not None: |
59 return d | 59 return d |
60 time.sleep(try_time) | 60 time.sleep(try_time) |
61 return None | 61 return None |
62 | 62 |
63 new_f.func_name = func.func_name | 63 new_f.__name__ = func.__name__ |
64 return new_f | 64 return new_f |
65 return inner | 65 return inner |
66 | 66 |
67 def readline(sock): | 67 def readline(sock): |
68 timeout = READLINE_SELECT_TIMEOUT | 68 timeout = READLINE_SELECT_TIMEOUT |
111 | 111 |
112 try: | 112 try: |
113 pid = os.fork() | 113 pid = os.fork() |
114 if pid > 0: | 114 if pid > 0: |
115 sys.exit(0) | 115 sys.exit(0) |
116 except OSError, e: | 116 except OSError as e: |
117 E("Bad fork()") | 117 E("Bad fork()") |
118 sys.exit(1) | 118 sys.exit(1) |
119 | 119 |
120 os.setsid() | 120 os.setsid() |
121 | 121 |
122 try: | 122 try: |
123 pid = os.fork() | 123 pid = os.fork() |
124 if pid > 0: | 124 if pid > 0: |
125 sys.exit(0) | 125 sys.exit(0) |
126 except OSError, e: | 126 except OSError as e: |
127 E("Bad fork()") | 127 E("Bad fork()") |
128 sys.exit(1) | 128 sys.exit(1) |
129 | 129 |
130 def uptime(): | 130 def uptime(): |
131 try: | 131 try: |
132 return float(open('/proc/uptime', 'r').read().split(' ', 1)[0]) | 132 return float(open('/proc/uptime', 'r').read().split(' ', 1)[0]) |
133 except Exception, e: | 133 except Exception as e: |
134 return -1 | 134 return -1 |
135 | 135 |