|
| 1 | +import logging |
1 | 2 | import os |
2 | 3 | import shutil |
3 | 4 | import ast |
| 5 | +import threading |
| 6 | +import time |
| 7 | +import sys |
| 8 | + |
4 | 9 | import astunparse |
5 | 10 | from pathlib import Path |
6 | 11 | import uuid |
@@ -105,14 +110,19 @@ def jupyter_dump(self): |
105 | 110 | jupyter_dump_ = ( |
106 | 111 | "import sys\n" |
107 | 112 | "import os\n" |
| 113 | + "import threading\n" |
108 | 114 | f"import {self.marshaller}\n" |
109 | | - "from jumper.userpersistence import dump_runtime,dump_variables\n" |
| 115 | + "from jumper.userpersistence import dump_runtime, dump_variables, spinner_task, stop_spinner_event\n" |
| 116 | + "spinner_thread = threading.Thread(target=spinner_task)\n" |
| 117 | + "spinner_thread.start()\n" |
110 | 118 | "dump_runtime(os.environ, sys.path," |
111 | 119 | f"'{self.paths['jupyter']['os_environ']}'," |
112 | 120 | f"'{self.paths['jupyter']['sys_path']}',{self.marshaller})\n" |
113 | 121 | f"dump_variables({str(self.jupyter_variables)},globals()," |
114 | 122 | f"'{self.paths['jupyter']['var']}'," |
115 | 123 | f"{self.marshaller})\n" |
| 124 | + "stop_spinner_event.set()\n" |
| 125 | + "spinner_thread.join()\n" |
116 | 126 | ) |
117 | 127 |
|
118 | 128 | return jupyter_dump_ |
@@ -368,3 +378,17 @@ def magics_cleanup(code): |
368 | 378 | ): # Line magic & executed cell, remove first word |
369 | 379 | nomagic_code = code.split(" ", 1)[1] |
370 | 380 | return scorep_env, nomagic_code |
| 381 | + |
| 382 | + |
| 383 | +stop_spinner_event = threading.Event() |
| 384 | + |
| 385 | + |
| 386 | +def spinner_task(message="Loading user input..."): |
| 387 | + spinner = ['|', '/', '-', '\\'] |
| 388 | + i = 0 |
| 389 | + while not stop_spinner_event.is_set(): |
| 390 | + sys.stdout.write(f'\r{message} {spinner[i % len(spinner)]}') |
| 391 | + sys.stdout.flush() |
| 392 | + time.sleep(0.1) |
| 393 | + i += 1 |
| 394 | + sys.stdout.write('\rUser input loaded! \n') |
0 commit comments