From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: sleep-for documentation and how to pause reliably Date: Fri, 15 Feb 2013 11:19:27 +0100 Organization: Emacs Helm Message-ID: <878v6pj2vk.fsf@gmail.com> References: <83mwv6szif.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1360923590 4792 80.91.229.3 (15 Feb 2013 10:19:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Feb 2013 10:19:50 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 15 11:20:12 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U6IOp-00015k-LT for ged-emacs-devel@m.gmane.org; Fri, 15 Feb 2013 11:20:11 +0100 Original-Received: from localhost ([::1]:53622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6IOV-0002Gb-V1 for ged-emacs-devel@m.gmane.org; Fri, 15 Feb 2013 05:19:51 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6IOP-0002GE-Fz for emacs-devel@gnu.org; Fri, 15 Feb 2013 05:19:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6IOJ-0006uE-9R for emacs-devel@gnu.org; Fri, 15 Feb 2013 05:19:45 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:57452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6IOJ-0006u6-2v for emacs-devel@gnu.org; Fri, 15 Feb 2013 05:19:39 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1U6IOZ-00011X-QD for emacs-devel@gnu.org; Fri, 15 Feb 2013 11:19:55 +0100 Original-Received: from lbe83-2-78-243-104-167.fbx.proxad.net ([78.243.104.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Feb 2013 11:19:55 +0100 Original-Received: from thierry.volpiatto by lbe83-2-78-243-104-167.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Feb 2013 11:19:55 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 57 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lbe83-2-78-243-104-167.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.93 (gnu/linux) Cancel-Lock: sha1:1BEixvvoVntYrXuKJX3G2P8sJyI= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157045 Archived-At: Hi Eli, Eli Zaretskii writes: > Am I missing something, or is our current docs of sleep-for misleading? > > The doc string says: > > (sleep-for SECONDS &optional MILLISECONDS) > > Pause, without updating display, for SECONDS seconds. > > The only way I can interpret this is that sleep-for _always_ pauses > for that number of seconds. > > The ELisp manual goes even further: > > -- Function: sleep-for seconds &optional millisec > This function simply pauses for SECONDS seconds without updating > the display. It pays no attention to available input. It returns > `nil'. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > [...] > > Use `sleep-for' when you wish to guarantee a delay. > ^^^^^^^^^^^^^^^^^ > > "Guarantee a delay". No "buts". > > However, in fact, sleep-for will return as soon as any input from any > subprocess arrives. E.g., try this in *scratch*: > > (progn (setq proc (start-process-shell-command "ls" nil "ls")) > (sleep-for 20) > (message "hi")) > > You will see no delay at all before the message is displayed. > > Am I missing something? If not, apart of fixing the docs, _is_ there > any way to wait reliably when async subprocesses are running and > producing output? What about using a sentinel? (progn (let ((proc (start-process-shell-command "ls" nil "ls"))) (set-process-sentinel proc #'(lambda (process event) (when (string= event "finished\n")) (sleep-for 20) (message "hi after 20s sleeping")))) (message "Hi now sleeping 20s")) -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997