简体   繁体   中英

Run different script with pypy3 or python

Is there a way to run the main script in pypy3, but an import, say helper.py to be executed/interpreted by regular python? And vice versa?

To clarify, let's say I have main.py that I want to execute with pypy3 . That script imports helper and I want the entire script in helper.py to be executed with python3 . Or vice versa. I was wondering if there's something like import pyximport; pyximport install() import pyximport; pyximport install() where the import is then compiled, basically work/act differently as the main.py. I was wondering if there's something like that, that I can do. Currently, I would use pypy3 main.py and within main.py, have subprocess.popen and execute python helper.py , and just pass an object or results through the stdout/pipe. Curious if there are other ways I could do this.

Yes, I know you would ask why even bother doing this. I am currently thinking of this since iterating a file with python in Windows is much faster than iterating a file line by line with pypy3. I know they are trying to update/fix this, but since it is not yet fixed, was wondering what I could do. In Linux, pypy3 works great, even in iterating a file.

I guess another scenario can be when a library is not supported in pypy3 yet, so you would want to still execute that script with python3, but maybe the other part of the scripts you may want to use pypy3 to gain some performance. Hope this question was clear.

Subprocess seems like the right way to go. There are however, humanized equivalent libraries for managing subprocesses that you could look at like,

  1. Delegator
  2. Envoy
  3. Pexpect

This feels like an interesting experiment to provide fallback support for libraries or functions that are not supported in one runtime environment, but can be executed in some other supported environment and still retain the linear flow of execution of the program.

How you would scale this? is an entirely different question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM