Browse Source

Update the examples for windows compat

Steven Silvester 8 years ago
parent
commit
529c7f23e7
2 changed files with 26 additions and 2 deletions
  1. 13 1
      examples/console/main.py
  2. 13 1
      examples/notebook/main.py

+ 13 - 1
examples/console/main.py

@@ -9,6 +9,11 @@ import threading
 
 import tornado.web
 
+# Install the pyzmq ioloop. This has to be done before anything else from
+# tornado is imported.
+from zmq.eventloop import ioloop
+ioloop.install()
+
 PORT = 8765
 
 
@@ -69,7 +74,14 @@ def main(argv):
                                   compiled_template_cache=False)
 
     app.listen(PORT, 'localhost')
-    loop = tornado.ioloop.IOLoop.instance()
+
+    if sys.platform.startswith('win'):
+        # add no-op to wake every 5s
+        # to handle signals that may be ignored by the inner loop
+        pc = ioloop.PeriodicCallback(lambda: None, 5000)
+        pc.start()
+
+    loop = ioloop.IOLoop.current()
     print('Browse to http://localhost:%s' % PORT)
     try:
         loop.start()

+ 13 - 1
examples/notebook/main.py

@@ -9,6 +9,11 @@ import threading
 
 import tornado.web
 
+# Install the pyzmq ioloop. This has to be done before anything else from
+# tornado is imported.
+from zmq.eventloop import ioloop
+ioloop.install()
+
 PORT = 8765
 
 
@@ -69,7 +74,14 @@ def main(argv):
                                   compiled_template_cache=False)
 
     app.listen(PORT, 'localhost')
-    loop = tornado.ioloop.IOLoop.instance()
+
+    if sys.platform.startswith('win'):
+        # add no-op to wake every 5s
+        # to handle signals that may be ignored by the inner loop
+        pc = ioloop.PeriodicCallback(lambda: None, 5000)
+        pc.start()
+
+    loop = ioloop.IOLoop.current()
     print('Browse to http://localhost:%s' % PORT)
     try:
         loop.start()