* about async process
@ 2018-08-25 18:15 akrl
2018-08-25 18:39 ` Eli Zaretskii
[not found] ` <mailman.5535.1535223078.1292.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 3+ messages in thread
From: akrl @ 2018-08-25 18:15 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
the question is: when is the process buffer updated after an async
process finish to execute?
This is what I'm trying to do:
(make-thread (lambda ()
(let ((prc
(start-process-shell-command "test"
"out-buff"
"echo foo")))
(while (not (equal (process-status prc)
'exit))
(thread-yield))
(with-current-buffer "out-buff"
(print (buffer-string))
(sleep-for 0.1)
(print (buffer-string))))))
I'm trying to execut an async process in a thread yielding till this has
finished and then reading the output.
When I execute this code the first print is printing "" and just the
second print after the sleep il latching the output I would expect.
So my question is when is the output buffer updated and if ther's a way to
ensure this has happend or to request for it?
Bests and thanks
Andrea
--
akrl@sdf.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: about async process
2018-08-25 18:15 about async process akrl
@ 2018-08-25 18:39 ` Eli Zaretskii
[not found] ` <mailman.5535.1535223078.1292.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2018-08-25 18:39 UTC (permalink / raw)
To: help-gnu-emacs
> From: akrl <akrl@sdf.org>
> Date: Sat, 25 Aug 2018 18:15:50 +0000
>
> the question is: when is the process buffer updated after an async
> process finish to execute?
When Emacs is idle. From the ELisp manual:
Output from a subprocess can arrive only while Emacs is waiting: when
reading terminal input (see the function ‘waiting-for-user-input-p’), in
‘sit-for’ and ‘sleep-for’ (*note Waiting::), and in
‘accept-process-output’ (*note Accepting Output::). This minimizes the
problem of timing errors that usually plague parallel programming. For
example, you can safely create a process and only then specify its
buffer or filter function; no output can arrive before you finish, if
the code in between does not call any primitive that waits.
> (make-thread (lambda ()
> (let ((prc
> (start-process-shell-command "test"
> "out-buff"
> "echo foo")))
> (while (not (equal (process-status prc)
> 'exit))
> (thread-yield))
> (with-current-buffer "out-buff"
> (print (buffer-string))
> (sleep-for 0.1)
> (print (buffer-string))))))
>
> I'm trying to execut an async process in a thread yielding till this has
> finished and then reading the output.
> When I execute this code the first print is printing "" and just the
> second print after the sleep il latching the output I would expect.
> So my question is when is the output buffer updated and if ther's a way to
> ensure this has happend or to request for it?
With this code, the first instance of Emacs becoming idle is when you
call sleep-for. Calls to thread-yield don't count as idling.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: about async process
[not found] ` <mailman.5535.1535223078.1292.help-gnu-emacs@gnu.org>
@ 2018-08-25 19:51 ` akrl
0 siblings, 0 replies; 3+ messages in thread
From: akrl @ 2018-08-25 19:51 UTC (permalink / raw)
To: help-gnu-emacs
Thanks Eli for the explanation, sorry if I missed the manual.
Bests
Andrea
--
akrl@sdf.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-25 19:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-25 18:15 about async process akrl
2018-08-25 18:39 ` Eli Zaretskii
[not found] ` <mailman.5535.1535223078.1292.help-gnu-emacs@gnu.org>
2018-08-25 19:51 ` akrl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).