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

my $queue1 = new Thread::Queue; #Thread Timeout Test my $command = 'diskpart'; #my ($thr) = threads->create(sub {return `$command`;}); my ($thr) = async{ my @resp1 :shared = `$command`; $queue1->enqueue(\@resp1, undef); return; }; threads->list(); my $count = 60 * 1; #wait a min (testing) while ($count and !$thr->is_joinable()) { sleep(1); count--; } if (!$thr->is_joinable()) { threads->exit(); } ...

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.


In reply to Re^12: Forking Clients by Anonymous Monk
in thread Forking Clients by gepapa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.