I'm running a bunch of python scripts from a directory, one after the
other.
I want to make sure that those scripts don't interfere with each other.
My code looks like this:
for(directory_iterator itr(filterDir);itr!=directory_iterator();++itr) {
if(itr->path().extension()==".py") {
try {
object global = import("__main__").attr("__dict__");
object sys = import("sys");
sys.attr("path").attr("append")(str(filterDir));
exec_file(str(itr->path().string()), global, global);
} catch(error_already_set const &) {
cout<<"Python syntax/runtime error."<
Christopher Harvey
I'm running a bunch of python scripts from a directory, one after the other. I want to make sure that those scripts don't interfere with each other. My code looks like this:
for(directory_iterator itr(filterDir);itr!=directory_iterator();++itr) { if(itr->path().extension()==".py") { [snip -- run the script in *itr, essentially.] }
Basically what I want to know is this: For every iteration of the exterior for loop will any of the scripts that are executed be able to impact in any way another script that is executed?
I don't think you could possibly know that; there's just too many possibilities. Consider: script1 script2 import os import os fd = os.open("/tmp/a", O_WRONLY) fd = os.open("/tmp/a", O_RDONLY) os.write(fd, "blah blah blah") str = os.read(fd, 42) os.close(fd) os.close(fd) To know that those scripts could interfere, or required an ordering, you would need to know what they did. Which would mean you would have to interpret them. That's the whole problem though, you want to make sure you don't get errors during interpretation. (While you're at it, try writing a program that can take any python program as input and tell you if it terminates. Definitely send me a ping back if you can figure that one out.) -tom
participants (2)
-
Christopher Harvey
-
tom fogal