|
8 | 8 | import traceback |
9 | 9 | import warnings |
10 | 10 | import weakref |
| 11 | +import html |
11 | 12 | from enum import Enum |
12 | 13 | from pathlib import Path |
13 | 14 | from typing import Any, Dict, List, Optional, cast |
14 | 15 |
|
15 | 16 | import ipywidgets as widgets |
16 | 17 | import reacton |
17 | 18 | from reacton.core import Element, render |
| 19 | +from reacton import ipywidgets |
18 | 20 |
|
19 | 21 | import solara |
20 | 22 | import solara.lifecycle |
|
26 | 28 |
|
27 | 29 | WebSocket = Any |
28 | 30 | apps: Dict[str, "AppScript"] = {} |
29 | | -thread_lock = threading.Lock() |
| 31 | +thread_lock = threading.RLock() |
30 | 32 |
|
31 | 33 | logger = logging.getLogger("solara.server.app") |
32 | 34 |
|
@@ -232,12 +234,22 @@ def check(self): |
232 | 234 |
|
233 | 235 | def run(self): |
234 | 236 | self.check() |
235 | | - if reload.reloader.requires_reload or self._first_execute_app is None: |
| 237 | + if self._first_execute_app is None: |
236 | 238 | with thread_lock: |
237 | | - if reload.reloader.requires_reload or self._first_execute_app is None: |
238 | | - self._first_execute_app = None |
239 | | - self._first_execute_app = self._execute() |
240 | | - print("Re-executed app", self.name) # noqa |
| 239 | + if self._first_execute_app is None: |
| 240 | + try: |
| 241 | + self._first_execute_app = self._execute() |
| 242 | + print("Re-executed app", self.name) # noqa |
| 243 | + except Exception as e: |
| 244 | + error = "" |
| 245 | + error = "".join(traceback.format_exception(None, e, e.__traceback__)) |
| 246 | + print(error, file=sys.stdout, flush=True) # noqa |
| 247 | + |
| 248 | + error = html.escape(error) |
| 249 | + self._first_execute_app = ipywidgets.HTML(value=f"<pre>{error}</pre>", layout=ipywidgets.Layout(overflow="auto")) |
| 250 | + # We now ran the app again, might contain new imports |
| 251 | + |
| 252 | + print("Failed to execute app, fix the error and save the file to reload") # noqa |
241 | 253 | # We now ran the app again, might contain new imports |
242 | 254 | patch.patch_heavy_imports() |
243 | 255 |
|
@@ -319,6 +331,9 @@ def reload(self): |
319 | 331 | except Exception as e: |
320 | 332 | logger.exception("Could not close render context: %s", e) |
321 | 333 |
|
| 334 | + self._first_execute_app = None |
| 335 | + self.run() |
| 336 | + |
322 | 337 | # ask all contexts/users to reload |
323 | 338 | for context in context_values: |
324 | 339 | with context: |
|
0 commit comments