From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: about async process Date: Sat, 25 Aug 2018 21:39:53 +0300 Message-ID: <83in3y70jq.fsf@gnu.org> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1535222986 1948 195.159.176.226 (25 Aug 2018 18:49:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 25 Aug 2018 18:49:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 25 20:49:42 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ftdd0-0000Pz-DO for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Aug 2018 20:49:42 +0200 Original-Received: from localhost ([::1]:46755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftdf6-0006uW-Pq for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Aug 2018 14:51:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftdeT-0006lZ-L0 for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 14:51:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftdTg-0006ct-FO for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 14:40:08 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftdTg-0006cl-Bg for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 14:40:04 -0400 Original-Received: from [176.228.60.248] (port=3488 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ftdTf-0001x2-LU for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 14:40:04 -0400 In-reply-to: (message from akrl on Sat, 25 Aug 2018 18:15:50 +0000) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117737 Archived-At: > From: akrl > 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.