<br><br><div><span class="gmail_quote">On 6/27/06, <b class="gmail_sendername">Jim Jewett</b> &lt;<a href="mailto:jimjjewett@gmail.com">jimjjewett@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(1)&nbsp;&nbsp;Is it impossible for an interpreter to switch between trusted and<br>untrusted modes?&nbsp;&nbsp;This is probably a reasonable restriction, but worth<br>calling out loudly in the docs.</blockquote><div><br>Yes, you should not change the state once the interpreter is used for execution. 
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(2)&nbsp;&nbsp;For the APIs returning an int, it wasn't clear what that int<br>would be, other than NULL =&gt; interpreter is trusted.
</blockquote><div><br>Doesn't matter.&nbsp; I should probably change it to a say &quot;a false value&quot; instead of NULL. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm not sure that NULL is even always the best answer when the<br>interpreter is trusted.&nbsp;&nbsp;For example, if I called PyXXX_AllowFile, I<br>want to know whether the file is now allowed; I don't really care that<br>it is allowed because the interpreter is trusted anyhow.
</blockquote><div><br>It's a question of whether you want that interpretation or want to make sure you never call the restriction setters on trusted interpreters.&nbsp; Anyone else have a preference like Jim?<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(3)&nbsp;&nbsp;Should PyXXX_Trusted have a variant that takes group/type/string,<br>meaning &quot;Am I allowed to do *this*?&quot;, rather than having to<br>special-case the &quot;You can do anything&quot; case?</blockquote><div><br>
The PyXXX_Trusted() case is meant as a blanket trusted/untrusted test.&nbsp; If you want more fine-grained, use the other checking functions (e.g., PyXXX_ExtendedCheckValue(), etc.).&nbsp; As I mention in the docs, if you want a &quot;am I allowed to do this, if not I want to do something else&quot;, wrap the checking functions in another function and check that function's return value::
<br><br>&nbsp; int<br>&nbsp; check_for_value(group, type, string)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; PyXXX_ExtendedCheckValue(group, type, string, 0);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(4)&nbsp;&nbsp;For capped resources, there needs to be a way to tell what that<br>cap is, and how much is left.&nbsp;&nbsp;(Logically, this provides &quot;how much is<br>already used&quot;, which is already a frequently requested feature for
<br>memory.)</blockquote><div><br>Fair enough.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">One use of untrusted interpreters is to stop runaway processes.&nbsp;&nbsp;For
<br>example, it might always be OK to add 4M memory, so long as it has<br>been at least 10 seconds since the last request.&nbsp;&nbsp;This requires the<br>controller to know what the current setting is.<br><br>Caps and current usage should also be available (though read-only)
<br>from python; it is quite sensible to spill some cache when getting too<br>close to your memory limit.</blockquote><div><br>Yeah, being able to read your restrictions seems reasonable to do from an untrusted interpreter. 
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(5)&nbsp;&nbsp;I think file creation/writing should be capped rather than<br>binary; it is reasonable to say &quot;You can create a single temp file up
<br>to 4K&quot; or &quot;You can create files, but not more than 20Meg total&quot;.</blockquote><div><br>That has been suggested before.&nbsp; Anyone else like this idea?<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(6)&nbsp;&nbsp;Given your expectation of one interpreter per web page,<br>interpreters will have to be very lightweight.&nbsp;&nbsp;This might be the real<br>answer to the CPU limiting -- just run each restricted interpreter as<br>its own &quot;thread&quot; (possibly not an OS-level thread), and let the
<br>scheduler switch it out.</blockquote><div><br>That's another possibility; having the OS's threading capabilities run individual instances of the interpreter in its own thread instead of having Python manage all of the interpreters itself.&nbsp; I just don't know how feasible that is based on how Python is designed to be embedded and has so much global state.
<br><br>Thanks for the feedback, Jim!<br><br>-Brett<br></div></div>