all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* call-process should not block process filters from running
@ 2023-06-27 21:55 Spencer Baugh
  2023-06-28 11:39 ` Mattias Engdegård
                   ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Spencer Baugh @ 2023-06-27 21:55 UTC (permalink / raw)
  To: emacs-devel; +Cc: app-emacs-dev


When Lisp code calls call-process, then while call-process is running,
all Lisp is blocked from running, including process filters and timers
created beforehand by other Lisp.  This call-process behavior is
harmful, but we can fix call-process to not behave this way.

This call-process behavior is harmful:
Many packages rely on their process filters and timers being able to
run:
- Packages which communicate over the network (such as ERC)
  rely on being able to respond to heartbeats and prevent timeouts.
- Packages which respond to requests from other programs (such as EXWM)
  rely on being able to respond to those requests.
A simple (shell-command "sleep 60") will cause most such packages to
break or behave poorly.

We can fix call-process to not behave this way:
It is straightforward to reimplement call-process in Lisp, using
accept-process-output, so that process filters and timers and other Lisp
can run while waiting on call-process.  There's been at least one
attempt at doing so:
https://github.com/tromey/emacs/tree/rewrite-call-process

My suggestion is that we should create a new helper function in Lisp,
perhaps called "process-run", which has an identical interface as
call-process, except that while it is running, other process filters and
other Lisp are still able to run.  Then we can move users of
call-process over to this new function.  Most (but perhaps not all) Lisp
using call-process should be using process-run, since most Lisp doesn't
actually want to block process filters from running.

As a bonus, process-run will be usable by Lisp code running in Lisp
threads created by make-thread, as will any functions which use
process-run, since accept-process-output supports threads.
(call-process does not)

A few clarifications in advance for things which I suspect might be
confusing:

- This is not about switching Lisp from running processes synchronously
  (call-process) to asynchronously (make-process).  process-run would
  still be a synchronous API.  It is much easier to fix this one bad
  aspect of the call-process API than to move lots of Lisp over to
  make-process.  Even if we moved all Lisp over to be run asynchronous
  processes, we would still want a fixed call-process for Lisp thread
  support.

- This does not require changing the C core of Emacs at all, nor
  changing the call-process implementation.  The existing
  accept-process-output API is sufficient for creating a synchronous
  process-running API which does not block Lisp from running in process
  filters and timers and so on.

- MS-DOS can't support an implementation of call-process which allows
  other Lisp to run.  On MS-DOS, call-process and process-run will be
  identical.  This is fine and not a problem.  Furthermore, even if it
  was a problem, MS-DOS should not hold us back from improving Emacs on
  other platforms.




^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2023-07-09  9:04 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-27 21:55 call-process should not block process filters from running Spencer Baugh
2023-06-28 11:39 ` Mattias Engdegård
2023-06-28 11:56 ` Po Lu
2023-06-28 12:08   ` Spencer Baugh
2023-06-28 13:17     ` Po Lu
2023-06-28 12:52 ` Eli Zaretskii
2023-06-28 13:27   ` Spencer Baugh
2023-06-28 13:34     ` Eli Zaretskii
2023-07-01 18:24     ` Spencer Baugh
2023-07-01 18:59       ` Eli Zaretskii
2023-07-01 19:17         ` Spencer Baugh
2023-07-02  5:45           ` Eli Zaretskii
2023-07-03  0:02             ` sbaugh
2023-07-03 10:00               ` Po Lu
2023-07-03 17:53                 ` sbaugh
2023-07-03 18:51                   ` Eli Zaretskii
2023-07-03 20:28                     ` sbaugh
2023-07-04  4:12                       ` Po Lu
2023-07-04 11:25                         ` Eli Zaretskii
2023-07-04 12:42                         ` sbaugh
2023-07-04 13:42                           ` Michael Albinus
2023-07-04 14:16                             ` sbaugh
2023-07-05  6:36                               ` Michael Albinus
2023-07-04 11:10                       ` Eli Zaretskii
2023-07-04 12:20                         ` sbaugh
2023-07-04 13:09                           ` Eli Zaretskii
2023-07-04 13:37                             ` sbaugh
2023-07-04 13:25                           ` Po Lu
2023-07-04  1:04                     ` sbaugh
2023-07-04  4:09                       ` Po Lu
2023-07-04 12:27                         ` sbaugh
2023-07-04 13:22                           ` Po Lu
2023-07-04 13:51                             ` sbaugh
2023-07-04 16:38                               ` Eli Zaretskii
2023-07-04 16:53                                 ` sbaugh
2023-07-04 17:14                                   ` Eli Zaretskii
2023-07-04 16:49               ` Dmitry Gutov
2023-07-04 18:12                 ` sbaugh
2023-07-05 18:53                   ` Dmitry Gutov
2023-07-06  2:24                     ` sbaugh
2023-07-06  8:06                       ` Michael Albinus
2023-07-08 15:54                         ` sbaugh
2023-07-09  9:04                           ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.