Groups | Search | Server Info | Login | Register
Groups > comp.lang.tcl > #55667
| From | Mark Summerfield <m.n.summerfield@gmail.com> |
|---|---|
| Newsgroups | comp.lang.tcl |
| Subject | Re: Fastest way to run two external processes |
| Date | 2026-04-29 08:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <10ssgq5$3nvs2$2@dont-email.me> (permalink) |
| References | <10sschf$3nvs2$1@dont-email.me> |
On Wed, 29 Apr 2026 07:38:23 -0000 (UTC), Mark Summerfield wrote:
> I need to run two external processes (on Linux):
>
> pdftotext -tsv one.pdf
> pdftotext -tsv two.pdf
>
> For each one I need to acquire the output and post-process it.
> Both are completely independent.
> (However, once I've finished post-processing I then do some work on
> both sets of post-processed data together.)
>
> Each external process takes about 3 secs so it takes just over 6 secs
> to acquire the data from both processes.
>
> When I've done something similar in Python I've used the multiprocessing
> module and this has got my runtime close to the 3 secs.
>
> In my experiments with Tcl's threading I've found the threading startup
> overhead to be rather large.
>
> What is the fastest way to run two independent processes concurrently
> and acquire their outputs using Tcl?
Here's my serial version:
proc app::serial {pdftotext pdf1 pdf2} {
puts serial
set pdf1tsv [exec $pdftotext -tsv $pdf1 -]
set pdf2tsv [exec $pdftotext -tsv $pdf2 -]
list $pdf1tsv $pdf2tsv
}
This takes ~2 sec for two ~650 page PDFs.
With some help from Gemini (after I got past non-working and slow
solutions) I did a multiprocessing version:
proc app::multiprocess {pdftotext pdf1 pdf2} {
set p1 [open "|$pdftotext -tsv $pdf1 - 2>@1" r]
try {
set p2 [open "|$pdftotext -tsv $pdf2 - 2>@1" r]
try {
fconfigure $p1 -blocking 0
fconfigure $p2 -blocking 0
set pdf1tsv ""
set pdf2tsv ""
while {![eof $p1] || ![eof $p2]} {
append pdf1tsv [read $p1]
append pdf2tsv [read $p2]
after 1
}
} finally {
close $p2
}
} finally {
close $p1
}
list $pdf1tsv $pdf2tsv
}
This takes ~1 sec.
Back to comp.lang.tcl | Previous | Next — Previous in thread | Next in thread | Find similar
Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-04-29 07:38 +0000
Re: Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-04-29 08:51 +0000
Re: Fastest way to run two external processes meshparts <alexandru.dadalau@meshparts.de> - 2026-04-29 11:24 +0200
Re: Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-04-29 09:46 +0000
Re: Fastest way to run two external processes Ralf Fassel <ralfixx@gmx.de> - 2026-04-29 12:30 +0200
Re: Fastest way to run two external processes abu <user13892@newsgrouper.org.invalid> - 2026-04-30 00:51 +0000
Re: Fastest way to run two external processes Ralf Fassel <ralfixx@gmx.de> - 2026-04-30 14:23 +0200
Re: Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-05-01 07:04 +0000
Re: Fastest way to run two external processes Ralf Fassel <ralfixx@gmx.de> - 2026-05-01 22:54 +0200
Re: Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-05-02 06:57 +0000
Re: Fastest way to run two external processes Ashok <apnmbx-public@yahoo.com> - 2026-05-09 16:03 +0530
Re: Fastest way to run two external processes Ralf Fassel <ralfixx@gmx.de> - 2026-05-11 11:08 +0200
Re: Fastest way to run two external processes Mark Summerfield <m.n.summerfield@gmail.com> - 2026-05-12 08:40 +0000
Re: Fastest way to run two external processes Ralf Fassel <ralfixx@gmx.de> - 2026-05-12 16:58 +0200
Re: Fastest way to run two external processes Olivier <user1108@newsgrouper.org.invalid> - 2026-05-01 10:06 +0000
Re: Fastest way to run two external processes Emiliano <emiliano@example.invalid> - 2026-05-02 00:34 -0300
csiph-web