]> git.eshelyaron.com Git - sweep.git/commitdiff
Check that top-level thread is alive when signaling it
authorEshel Yaron <me@eshelyaron.com>
Fri, 15 Sep 2023 08:08:04 +0000 (10:08 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 15 Sep 2023 08:08:04 +0000 (10:08 +0200)
* sweeprolog.el (sweeprolog-top-level-signal-current): Delete stale
pty "process" when trying to signal a top-level thread that has
already exited.

sweeprolog.el

index ada99c51bfd37f89d8939dc807d24f9eaf409567..b2fbcd5a61b2c39f67268ca7a9784a3276fe8141 100644 (file)
@@ -3262,7 +3262,21 @@ GOAL.  Otherwise, GOAL is set to a default value specified by
                        sweeprolog-top-level-signal-default-goal)))
   (unless sweeprolog-top-level-thread-id
     (sweeprolog-top-level--populate-thread-id))
-  (sweeprolog-signal-thread sweeprolog-top-level-thread-id goal))
+  (when (and (or (not sweeprolog-top-level-thread-id)
+                 (eq (condition-case error
+                         (sweeprolog-signal-thread sweeprolog-top-level-thread-id goal)
+                       (prolog-exception
+                        (pcase error
+                          (`(prolog-exception
+                             compound "error"
+                             (compound "existence_error" (atom . "thread") ,_)
+                             .
+                             ,_)
+                           'no-thread))))
+                     'no-thread))
+             sweeprolog-top-level-use-pty)
+    (delete-process (get-buffer-process
+                     (current-buffer)))))
 
 ;;;###autoload
 (define-derived-mode sweeprolog-top-level-mode comint-mode "Sweep Top-level"