Hello all,
I am in a group writing yet another webserver in Perl. This server uses Thread.pm (adaptive pre-threading server). This server has embedded perl pages (like a higher level PHP).
There are "Very Good Reasons" (outside the scope of a simple http daemon) for this being a threaded implementation.
My problem is that I wish to eval() the embedded perl code (yes with Safe.pm) so that said eval() will timeout (in say X seconds), printing whatever had been produced thus-far, with an appropriate timeout error message.
I first thought about alarm(), but quickly realised that signals cannot be delivered to specific threads.
I then tried reusing a pre-existing "monitor" thread in the server to kill off individual threads after a timeout period. Unfortunately, as there is no "kill thread" method or easily forseeable alternative, I had to periodically poll the "monitor" thread from each child.... which of course does not help for killing off a child who is performing some non-deterministic perl user-code.
I toyed with async(), and Time::HiRes, but thusfar have not found the "easy" way I seek. (The embedded perl code, and a timer , race to lock a per-thread scalar, the output or error is printed, the losing-thread is cleaned up).
If anyone has any suggestions, I would be supremely grateful. Either concepts or real code is fine.
PS: I am not too concerned about malicious user code crashing the server, as for applications "not audited by the administrator", the server will fork() a whole new threaded server... which will or won't die.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.