Forum > Packages and Libraries

Threaded TProcess?

(1/1)

lucamar:
A quick question: Is there somewhere a variant of TProcess but running on its own thread (kind of TThreadedProcess)? Or do I have to BMO?

Yeah, I know it's an easy task but if I can avoid doing it ... 8-)

winni:
Hi!

https://forum.lazarus.freepascal.org/index.php?topic=23455.0

Winni

lucamar:
Thanks Winni, interesting reading but ... I already have that forum thread saved to my "info" folder and I do know how to build what I want, up to making a component with it ;)
(Yah, I know: "famous last words" :D)

I only wanted to know if there was something like that ready-made so as to don't waste time doing it myself. Pure laziness, more than anything else ;D

marcov:
The problem is that you have at least two potentially blocking operations, read (from stdout/stderr) and write  (to stdin of the process). So will one thread be enough ? If one blocks a really long time the other will be starved.

As fedkad correctly remarked in the this morning's thread there is no easy solution to the write problem, but the read problem is abstracted by checking if it would block before reading (e.g. in runcommandloop)

lucamar:
Yeah, I've been following that thread with full attention precisely because I am in the planning stages of my component. I think it can be done with just one thread but that's just a "feeling" yet.

Anyway, for the first use it is being designed we'll not be needing reading/writing from the process pipes so we can go ahead with a minimalist design. Heck, we could probably even just call RunCommand() in the thread and ignore outputstring though
we are (or rather I am) going to use a full TProcess so that we can terminate or kill it at will if the need arise, etc. I.e. because I like having full control (or as much as possible) of external things, in case they go haywire.

And, of course, because if you set out to make a thing like this you may as well do it right :D

Though I would much prefer spending the weekend otherwise, TBH. Thence this thread ;D

Navigation

[0] Message Index

Go to full version