(cls)
| 252 | |
| 253 | @classmethod |
| 254 | def start(cls): |
| 255 | import asyncio |
| 256 | try: |
| 257 | asyncio.get_running_loop() |
| 258 | except RuntimeError: |
| 259 | pass |
| 260 | else: |
| 261 | cls.started = True |
| 262 | |
| 263 | if cls.started: |
| 264 | return |
| 265 | |
| 266 | """ |
| 267 | IOLoop.running() was removed as of Tornado 2.4; see for example |
| 268 | https://groups.google.com/forum/#!topic/python-tornado/QLMzkpQBGOY |
| 269 | Thus there is no correct way to check if the loop has already been |
| 270 | launched. We may end up with two concurrently running loops in that |
| 271 | unlucky case with all the expected consequences. |
| 272 | """ |
| 273 | ioloop = tornado.ioloop.IOLoop.instance() |
| 274 | |
| 275 | def shutdown(): |
| 276 | ioloop.stop() |
| 277 | print("Server is stopped") |
| 278 | sys.stdout.flush() |
| 279 | cls.started = False |
| 280 | |
| 281 | @contextmanager |
| 282 | def catch_sigint(): |
| 283 | old_handler = signal.signal( |
| 284 | signal.SIGINT, |
| 285 | lambda sig, frame: ioloop.add_callback_from_signal(shutdown)) |
| 286 | try: |
| 287 | yield |
| 288 | finally: |
| 289 | signal.signal(signal.SIGINT, old_handler) |
| 290 | |
| 291 | # Set the flag to True *before* blocking on ioloop.start() |
| 292 | cls.started = True |
| 293 | |
| 294 | print("Press Ctrl+C to stop WebAgg server") |
| 295 | sys.stdout.flush() |
| 296 | with catch_sigint(): |
| 297 | ioloop.start() |
| 298 | |
| 299 | |
| 300 | def ipython_inline_display(figure): |
no test coverage detected