diff --git a/docs/gen_reference_doc.py b/docs/gen_reference_doc.py index c756f948d..c489f366e 100644 --- a/docs/gen_reference_doc.py +++ b/docs/gen_reference_doc.py @@ -571,7 +571,7 @@ def parse_enum(lno, lines, filename): if '=' in v: val = int(v.split('=')[1].strip(), 0) valstr = str(val) - except BaseException: + except Exception: pass if '=' in v: diff --git a/examples/run_benchmarks.py b/examples/run_benchmarks.py index 0151fddc7..5c135cdb7 100755 --- a/examples/run_benchmarks.py +++ b/examples/run_benchmarks.py @@ -70,7 +70,7 @@ test_duration = 200 # 700 try: if os.name == 'posix': resource.setrlimit(resource.RLIMIT_NOFILE, (4000, 5000)) -except BaseException: +except Exception: if resource.getrlimit(resource.RLIMIT_NOFILE)[0] < 4000: print('please set ulimit -n to at least 4000') sys.exit(1) @@ -131,7 +131,7 @@ def build_commandline(config, port): if config['build'] == 'utorrent': try: os.mkdir('utorrent_session') - except BaseException: + except Exception: pass cfg = open('utorrent_session/settings.dat', 'w+') @@ -158,11 +158,11 @@ def build_commandline(config, port): cfg.close() try: os.mkdir('utorrent_session/autoload') - except BaseException: + except Exception: pass try: shutil.copy(torrent_path, 'utorrent_session/autoload/') - except BaseException: + except Exception: pass return './utorrent-server-v3_0/utserver -logfile session_stats/alerts_log.txt -settingspath utorrent_session' @@ -172,12 +172,12 @@ def build_commandline(config, port): else: try: os.mkdir('rtorrent_session') - except BaseException: + except Exception: pass # it seems rtorrent may delete the original torrent when it's being added try: shutil.copy(torrent_path, 'rtorrent_session/') - except BaseException: + except Exception: pass add_command = '-O load_start_verbose=rtorrent_session/%s ' % torrent_path @@ -198,14 +198,14 @@ def delete_files(files): for i in files: try: os.remove(i) - except BaseException: + except Exception: try: shutil.rmtree(i) - except BaseException: + except Exception: try: if os.path.exists(i): print('failed to delete %s' % i) - except BaseException: + except Exception: pass # typically the schedulers available are 'noop', 'deadline' and 'cfq' @@ -284,7 +284,7 @@ def find_library(name): try: if os.path.exists(p + name): return p + name - except BaseException: + except Exception: pass return name @@ -296,7 +296,7 @@ def find_binary(names): try: if os.path.exists(p + n): return p + n - except BaseException: + except Exception: pass return names[0] @@ -331,7 +331,7 @@ def run_test(config): try: os.mkdir('session_stats') - except BaseException: + except Exception: pass # save off the command line for reference @@ -402,7 +402,7 @@ def run_test(config): try: print('killing client') client.send_signal(signal.SIGINT) - except BaseException: + except Exception: pass time.sleep(10) @@ -420,16 +420,16 @@ def run_test(config): try: shutil.copy('asserts.log', 'session_stats/') - except BaseException: + except Exception: pass try: shutil.move('libtorrent_logs0', 'session_stats/') - except BaseException: + except Exception: pass try: shutil.move('libtorrent_logs%s' % port, 'session_stats/') - except BaseException: + except Exception: pass # run fragmentation test @@ -437,13 +437,13 @@ def run_test(config): os.system('./stage_aio/fragmentation_test test.torrent %s' % (config['save-path'])) try: shutil.copy('fragmentation.log', 'session_stats/') - except BaseException: + except Exception: pass shutil.copy('fragmentation.gnuplot', 'session_stats/') try: shutil.copy('file_access.log', 'session_stats/') - except BaseException: + except Exception: pass os.system('filefrag %s >session_stats/filefrag.out' % config['save-path']) @@ -468,7 +468,7 @@ def run_test(config): profile = 'session_stats/heap_profile.prof.%04d.heap' % i try: os.stat(profile) - except BaseException: + except Exception: break print('analyzing heap profile [%s] %d' % (binary, i)) os.system('%s --pdf %s %s >session_stats/heap_profile_%d.pdf' % diff --git a/test/http.py b/test/http.py index 26c197e0f..ce21fc804 100755 --- a/test/http.py +++ b/test/http.py @@ -91,7 +91,7 @@ import errno # Python 3 renamed thread module to _thread try: import _thread as thread -except BaseException: +except Exception: import thread __version__ = '0.1.0 Draft 1' @@ -125,7 +125,7 @@ class ConnectionHandler: elif self.method in ('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE'): self.method_others() - except BaseException: + except Exception: try: self.client.send(HTTPVER + ' 502 Connection failed\n' + 'Proxy-agent: %s\n\n' % VERSION) diff --git a/test/socks.py b/test/socks.py index 461fd0fd2..5784af3f2 100755 --- a/test/socks.py +++ b/test/socks.py @@ -11,7 +11,7 @@ import sys # Python 3 renamed SocketServer to socketserver try: from socketserver import StreamRequestHandler, ThreadingTCPServer -except BaseException: +except Exception: from SocketServer import StreamRequestHandler, ThreadingTCPServer @@ -51,7 +51,7 @@ def send(dest, msg): if msg == CLOSE: try: dest.shutdown(socket.SHUT_WR) - except BaseException: + except Exception: pass dest.close() return 0 diff --git a/test/web_server.py b/test/web_server.py index abbe327c9..7b5893a66 100644 --- a/test/web_server.py +++ b/test/web_server.py @@ -25,7 +25,7 @@ try: f.writelines(fin) f.close() fin.close() -except BaseException: +except Exception: pass diff --git a/tools/parse_dht_rtt.py b/tools/parse_dht_rtt.py index 6629cfe13..97e889557 100755 --- a/tools/parse_dht_rtt.py +++ b/tools/parse_dht_rtt.py @@ -21,7 +21,7 @@ for line in f: if (time < 0 or time > max_rtt - quantize): continue num_messages += 1 - time /= quantize + time //= quantize time *= quantize distribution[time] += 1 diff --git a/tools/parse_lookup_log.py b/tools/parse_lookup_log.py index d221c81ad..186a897bb 100755 --- a/tools/parse_lookup_log.py +++ b/tools/parse_lookup_log.py @@ -34,7 +34,7 @@ def plot_nodes(nodes, frame): try: os.mkdir('dht_frames') - except BaseException: + except Exception: pass out = open('dht_frames/plot-%02d.dot' % frame, 'w+') diff --git a/tools/parse_utp_log.py b/tools/parse_utp_log.py index ce8b70308..0531a88b4 100755 --- a/tools/parse_utp_log.py +++ b/tools/parse_utp_log.py @@ -91,7 +91,7 @@ metrics = { 'recv_buffer': ['receive buffer size (B)', 'x1y1', 'lines'] } -histogram_quantization = 1 +histogram_quantization = 1.0 socket_index = None columns = [] @@ -202,7 +202,7 @@ out.close() out = open('%s.histogram' % out_file, 'wb') for d, f in delay_histogram.items(): - print(float(d * histogram_quantization) + histogram_quantization / 2, f, file=out) + print(float(d * histogram_quantization) + histogram_quantization / 2.0, f, file=out) out.close() out = open('%s_packet_size.histogram' % out_file, 'wb')