unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Nicolas Richard <theonewiththeevillook@yahoo.fr>
Cc: 15695@debbugs.gnu.org
Subject: bug#15695: 24.3; multiple async shell commands at once run randomly
Date: Mon, 29 Jan 2018 08:52:50 -0500	[thread overview]
Message-ID: <87wp00ixfx.fsf@users.sourceforge.net> (raw)
In-Reply-To: <877gd3ofhy.fsf@yahoo.fr> (Nicolas Richard's message of "Wed, 23 Oct 2013 23:15:53 +0200")

retitle 15695 Incomplete data from subprocesses with pty connections
quit

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

>   (defvar statistics nil "Hash table for keeping statistics")
>   (defun yf/keep-stats (process change) "Used as sentinel"
>     (with-current-buffer (process-buffer process)
>       (if (equal change "finished\n")
>           (puthash (buffer-string) (1+ (or (gethash (buffer-string) statistics) 0)) statistics)
>         (error "Unknown change for process %s: %s" process change))))
>   (defun yf/pp-hash-table (hashtable) "Pretty print hash table"
>     (let ((res))
>       (maphash (lambda (k v) (setq res (concat res (yf/pp-hash--line k v)))) hashtable)
>       (or res "")))
>   (defun yf/pp-hash--line (key value) "Pretty print one hash line"
>     (format "%s: %s\n" (pp key) (pp value)))
>   (progn 
>     (let ((n 820))
>       (setq statistics (make-hash-table :test 'equal))
>       (dotimes (i n)
>         (let* ((buffername (concat "Shell-test" (number-to-string i)))
>                (buffer (get-buffer-create buffername)))
>           (with-current-buffer buffer
>             (erase-buffer))
>           (set-process-sentinel
>            (start-process buffername
>                           buffer
>                           shell-file-name
>                           shell-command-switch "echo foo&echo bar&echo baz")
>            #'yf/keep-stats)))
>       t)
>     (sit-for 2)
>     (insert (yf/pp-hash-table statistics)))

If I set process-connection-type to nil, then I get expected results
(though I had to reduce n in order to avoid bumping into the file
descriptor limit):

"baz\nfoo\nbar\n": 58
"baz\nbar\nfoo\n": 41
"foo\nbaz\nbar\n": 1

Without setting process-connection-type (all tests with 26.0.91):

"baz\n": 86
"baz\nbar\n": 5
"baz\nfoo\n": 6
"foo\nbaz\n": 1
"baz\nfoo\nbar\n": 2

This problem is also talked about in [1] and [2].

[1]: http://nullprogram.com/blog/2018/01/17/
[2]: http://nullprogram.com/blog/2014/02/06/#pseudo-terminals





  parent reply	other threads:[~2018-01-29 13:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-23 21:15 bug#15695: 24.3; multiple async shell commands at once run randomly Nicolas Richard
2013-10-24  7:07 ` Glenn Morris
2018-01-29 13:52 ` Noam Postavsky [this message]
2018-04-02 23:49   ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wp00ixfx.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=15695@debbugs.gnu.org \
    --cc=theonewiththeevillook@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

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).