]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
demos/benchmark: use current() instead of instance()
authorBen Darnell <ben@bendarnell.com>
Sun, 10 Jul 2016 13:54:22 +0000 (09:54 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 10 Jul 2016 13:54:22 +0000 (09:54 -0400)
Improves compatibility with some IOLoop implementations.

demos/benchmark/benchmark.py

index 6a0354d35f5f471f408101b5b1794ffc94394a52..1e8375d728a1bdab376ba7fab40c27339c5f6694 100755 (executable)
@@ -54,7 +54,7 @@ class RootHandler(RequestHandler):
         pass
 
 def handle_sigchld(sig, frame):
-    IOLoop.instance().add_callback_from_signal(IOLoop.instance().stop)
+    IOLoop.current().add_callback_from_signal(IOLoop.current().stop)
 
 def main():
     parse_command_line()
@@ -64,6 +64,7 @@ def main():
         run()
 
 def run():
+    io_loop = IOLoop(make_current=True)
     app = Application([("/", RootHandler)])
     port = random.randrange(options.min_port, options.max_port)
     app.listen(port, address='127.0.0.1')
@@ -78,10 +79,9 @@ def run():
         args.append("-q")
     args.append("http://127.0.0.1:%d/" % port)
     subprocess.Popen(args)
-    IOLoop.instance().start()
-    IOLoop.instance().close()
-    del IOLoop._instance
-    assert not IOLoop.initialized()
+    io_loop.start()
+    io_loop.close()
+    io_loop.clear_current()
 
 if __name__ == '__main__':
     main()