I have a python script that imports modules and that modules are importing top level modules this process takes long period of time, over 5 seconds. Is there a way in python to import modules once and reuse it for several times? Is it possible to avoid re importing python modules when you exit your script and rerun your script again?
Asked
Active
Viewed 73 times
0
-
1No, that's not possible. – Aran-Fey Oct 11 '19 at 10:57
-
@Aran-Fey is a way to run a python script like service and this python script gets some argument and returns output – student Oct 11 '19 at 11:03
-
You could create a loop that does what you want and maybe require a keypress each time. Really depends what your script is doing. – Frederik Højlund Oct 11 '19 at 11:05
-
@FrederikHøjlund how i can run my python script that takes a an argument as http POST and returns it to caller – student Oct 11 '19 at 11:07
-
You could take a look at Pythons HTTP Server: https://docs.python.org/3/library/http.server.html – Frederik Højlund Oct 11 '19 at 11:14
-
@FrederikHøjlund http.server is not recommended for production. It only implements basic security checks . – student Oct 11 '19 at 11:17
-
1This may point into an interesting direction for you: https://stackoverflow.com/questions/471191/why-compile-python-code – Jens Oct 11 '19 at 11:21
-
You will have to put the path to the modules into your environmental variables path – an4s911 Oct 11 '20 at 11:34