in reply to Re^9: Forking Clients
in thread Forking Clients
If I was at the point where I needed the information, I would wait for some specified amount of time. If it timesout I would kill the process and most likely die.
Could you expand upon the use of the handles, I can't say I have ever used this way of doing things. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^11: Forking Clients
by BrowserUk (Patriarch) on Oct 16, 2008 at 15:28 UTC | |
The point I've being trying to arrive at is that if, once you get to the point of needing the information, you have nothing else to do but wait for it to be available, then you do not need to do anything special. The handles in this case are simply the thread handles:
There are 3 things to note here:
The trick with threading, is that your code, at each level, should operate synchronously first. Then asynchronously. Depending upon the design of your library, you might also use a thread internally to achieve the timeout, but that is a separate issue from the main code. You should not conflate that timeout mechanism, however it is achieved, with the mechanism for running the methods asynchronously. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by gepapa (Acolyte) on Oct 16, 2008 at 17:57 UTC | |
This makes sense, thank you for your clear explanation and for sticking with me through all my questions. I assume in the instances where I don't need the information, lets say for example I kick of some command blindly, then I can just not do a join for it. Is this correct? Again thank you for your help, I will play with this more today, and post back my results and questions if I have any. | [reply] |
by BrowserUk (Patriarch) on Oct 16, 2008 at 18:09 UTC | |
I assume in the instances where I don't need the information, lets say for example I kick of some command blindly, then I can just not do a join for it. Is this correct? If there is nothing useful returned or you just aren't interested in what is, just detach it at the point of creation:
And any return will be discarded. If you're not sure if you will want the returns or not, start it in the normal way and decide later. If you want it, do the join. If you don't detach it as soon as you know that. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
by Anonymous Monk on Oct 21, 2008 at 14:44 UTC | |
As a followup, I have a separate issue that I think could be solved via threads as well. In certain instances, a system call might be made which in turn requires some user input, this system call will essentially hang there until the underlying process waiting for the response is killed. What I was hoping of doing was to create an asynchronous thread and have it run the command, I would loop for some set amount of time checking to see if the thread is joinable, if it is then great, if it times out then exit or kill the thread. I can't do the timeout in the function itself since there will be no response to the system call, that is why I am attempting to do it via thread that I can kill. The issue I am seeing is that after I launch the thread, anytime I attempt to do anything with the thread, i.e. to get information on it, it hangs. Any ideas? Thanks
The threads->list() call hangs (so does any other thread related call. If I do $command = 'dir'; everything works as expected since it is not stuck waiting for user input. | [reply] [d/l] |
by BrowserUk (Patriarch) on Oct 21, 2008 at 18:48 UTC | |
The simplest way to time out a system call is to use a thread with a piped open. See Re^3: Backticks and SIGALRM for one I prepared earlier :) Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |