Optimizing Python scripts' running time from C#

佐手、 提交于 2020-07-10 07:34:08

问题


I apologize in advance if my question is badly formulated, for I don't know if what I need makes any sense.

I'm currently working on a c# project where I need to run several time the same python script from inside the program, but with different arguments each time. For this, I'm not using IronPython, but the ProcessStartInfo class, for I understood that IronPython has some problem with certain packages I use. But this can change.

My problem is that although the python script is small and fast, it needs to import first a lot of packages, and this takes a lot of time. And therefore, my code is very slow, while 90% of the time is used to import python packages. I can't work around the problem by running this python script a single time with many arguments.

So is there a way to "open a permanent python console" from c#, where I could import everything once, then run the small script with my first argument, get the result back in c#, then run the script a second time etc .... ? Or any other way to optimize this ?

Thanks for your help,

Astrosias.

来源:https://stackoverflow.com/questions/62213494/optimizing-python-scripts-running-time-from-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!