Skip to content

Commit f170b82

Browse files
committed
[fix] make with-python-output & with-python-error-output more robust
1 parent 95053ce commit f170b82

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/python-process.lisp

+9-7
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ execution of THUNK as a string."
140140
(bt:with-recursive-lock-held (with-python-count-lock)
141141
(incf in-with-python-count)))
142142
(pycall (format nil "sys.~A.write" stderr-or-stdout) ".")
143-
(funcall thunk)
144-
(pycall (format nil "sys.~A.flush" stderr-or-stdout))
145-
(bt:signal-semaphore with-python-start-semaphore)
146-
(without-python-gil
147-
(bt:wait-on-semaphore with-python-end-semaphore))
148-
(setq all-signalled-p t)
143+
(unwind-protect
144+
(funcall thunk)
145+
(pycall (format nil "sys.~A.flush" stderr-or-stdout))
146+
(bt:signal-semaphore with-python-start-semaphore)
147+
(without-python-gil
148+
(bt:wait-on-semaphore with-python-end-semaphore))
149+
(setq all-signalled-p t))
149150
(let* ((output (get-output-stream-string with-python-stream))
150151
(len (length output)))
151152
(if (zerop len)
@@ -156,7 +157,8 @@ execution of THUNK as a string."
156157
(bt:signal-semaphore with-python-start-semaphore)
157158
(without-python-gil
158159
(bt:wait-on-semaphore with-python-end-semaphore)))
159-
(setf with-python-stream old-with-python-stream-value))))))
160+
(setf with-python-stream old-with-python-stream-value)
161+
(pycall (format nil "sys.~A.flush" stderr-or-stdout)))))))
160162

161163
;;; This is more of a global variable than a dynamic variable.
162164

0 commit comments

Comments
 (0)