Lazarus

Programming => Packages and Libraries => Topic started by: lucamar on August 05, 2021, 07:54:21 pm

Title: Threaded TProcess?
Post by: lucamar on August 05, 2021, 07:54:21 pm
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-)
Title: Re: Threaded TProcess?
Post by: winni on August 05, 2021, 09:45:30 pm
Hi!

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

Winni
Title: Re: Threaded TProcess?
Post by: lucamar on August 05, 2021, 10:35:55 pm
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
Title: Re: Threaded TProcess?
Post by: marcov on August 05, 2021, 10:48:03 pm
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  (https://forum.lazarus.freepascal.org/index.php/topic,55683.0.html) 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)
Title: Re: Threaded TProcess?
Post by: lucamar on August 06, 2021, 12:16:52 am
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
TinyPortal © 2005-2018