I am trying to find the best way to resume a Python script within me. It is currently working. Is built on START_CTX
.
This code relies in "caller" on code sys.argv [0]
. However, it fails in cases where it is done with:
dragon script.py ...
this case works Is:
dragon ./script.py ...
because the code before os.execlp Os.chdir uses
>.
I noticed os.environ ["_"]
, but I'm not sure how reliable it is. Another possible case is that if is not
and it is not executable and the PATH
on sys.argv [0] sys.executable
When using os.execlp
.
Any ideas better to solve this issue?
I think that the real issue here is that the GunQurn / Arbitrage code is always with the exact same environment Python wants to execute the script. This is important because the implementation of the Python script is an unknown and it is important because it is called exactly every time the same way.
My feeling is that the problem you are facing is what the intermediary has to do with the changing environment between the invention of the Python script.
-
We see that Python executables and args are being stored by Arbiter in itself.
-
Then we see that execvpe is called with sys.executable, modified organisms and then os.environ.
If os.environment was changed elsewhere (i.e. PWD variables), then your executable will be called properly (because you are no longer in the correct folder). It seems that the moderator takes care of this possibility by storing the CWD in START_CTX. So the question remains, why has the invocation failed for you?
I tried some trial code which I wrote:
#! / Usr / bin / env Python Import SYS import OS DIF main (): "" execute "" twice "" "cwd = os.getcwd () print CWD print sys.argv if os.path.exists (" / tmp / Start.txt "): OS. Unlink ("/ tmp / start.txt") Print "deleted /tmp/started.txt" print return arguments = [sys.executable] + sys.argv [:] os.system ("touch /tmp/started.txt ") Print" created /tmp/started.txt "print os.execvpe (sys.executable, args, os.environ) if __name__ == '__main__': main ()
when I execute this code from the command line, it works just fine:
guest @ desktop: ~ / Python / test $ python selfreferential.py / users / guest / Python / test [ 'Selfreferential.py'] was created /tmp/started.txt/users/thit/python/custom ['selfreferential.py'] deleted /tmp/started.txt guest @desktop: ~ / Python / test $ python ./ Selfrefe rentia L.py / users / guest / python / test ['./selfreferential.py'] Created /tmp/started.txt/ Users / guest / Python / test ['./selfreferential.py'] Deleted / TMP / Start Txt guest @ desktop: ~ / Python / test $ cd guest @ desktop: ~ $ python dragon / test / serference / user / guest ['python / test / swerfire'] / / / MTM / starred / youtube / guest [ 'Python / Test / SverreficialAlas'] deleted /tmp/started.txt Guest @Desktop: ~ $ python / Users / guides / Python / Test / Auto Viewer / User / Guest [' / User / Extra / Python / Test / SweeperialAppe '] Created /tmp/started.txt/user/host [' /Users/guest/Python/Test/selfreferential.py '] Deleted /tmp/started.txt Guest @Desktop: ~ $
As you can see, what Gunner was doing was not a problem. Therefore, there is something to do with environmental variables in your problem, or how your operating system can implement some things, there is nothing to do with it.
Comments
Post a Comment