|
8 | 8 |
|
9 | 9 | import ghpythonremote |
10 | 10 | from ghpythonremote.connectors import GrasshopperToPythonRemote |
| 11 | +from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error, Warning |
11 | 12 |
|
12 | 13 | local_log_level = getattr(logging, log_level, logging.WARNING) |
13 | 14 | logger = logging.getLogger("ghpythonremote") |
|
23 | 24 | ROOT = path.abspath(path.dirname(inspect.getfile(ghpythonremote))) |
24 | 25 | rpyc_server_py = path.join(ROOT, "pythonservice.py") |
25 | 26 |
|
| 27 | +cluster_comp = ghenv.Component.OnPingDocument().Owner |
| 28 | + |
26 | 29 | # Set connection to CLOSED if this is the first run |
27 | 30 | # and initialize set of linked modules |
28 | 31 | try: |
|
43 | 46 | pass |
44 | 47 | remote_python_status = "CLOSED" |
45 | 48 | lkd_modules = set() |
46 | | - raise RuntimeError( |
| 49 | + message = ( |
47 | 50 | "Connection left in an inconsistent state and not returning. Reset " |
48 | 51 | "everything." |
49 | 52 | ) |
| 53 | + if cluster_comp is not None: |
| 54 | + cluster_comp.AddRuntimeMessage(Warning, message) |
| 55 | + raise RuntimeError(message) |
50 | 56 |
|
51 | 57 | if run: |
52 | 58 | if not remote_python_status == "OPEN": |
|
73 | 79 | lkd_modules.add(mod) |
74 | 80 | except ImportError: |
75 | 81 | gh2py_manager.__exit__(*sys.exc_info()) |
| 82 | + if cluster_comp is not None: |
| 83 | + cluster_comp.AddRuntimeMessage( |
| 84 | + Error, |
| 85 | + 'Could not import module "{}" in remote Python.'.format(mod) |
| 86 | + ) |
| 87 | + raise |
| 88 | + except EOFError: |
| 89 | + if cluster_comp is not None: |
| 90 | + cluster_comp.AddRuntimeMessage( |
| 91 | + Error, |
| 92 | + 'Remote Python has been closed unexpectedly' |
| 93 | + ) |
76 | 94 | raise |
77 | 95 |
|
78 | 96 | elif not remote_python_status == "CLOSED": |
|
0 commit comments