Reputation: 67898
I have a setuptools-based Python (3.5) project with multiple scripts as entry points similar to the following:
entry_points={
'console_scripts': [
'main-prog=scripts.prog:main',
'prog-viewer=scripts.prog_viewer:main'
]}
So there is supposed to be a main script, run as main-prog
and an auxiliary script prog-viewer
(which does some Tk stuff).
The problem is that I want to be able to run the prog-viewer
in a Popen
subprocess from main-prog
(or rather form my library) without having to resort to manually figuring out the paths and then adapt to the different OS. Also, what do I do when my PATH contains a script with the same name that does not belong to my library? Can I tell my program to Popen(scripts.prog_viewer:main)
?
Upvotes: 1
Views: 563
Reputation: 18645
You could use the Multiprocessing module, which will also run your code as a subprocess. e.g.,
from multiprocessing import Process
from scripts.prog import main
# or
# from pkg_resources import load_entry_point
# main = load_entry_point('your-package', 'console_scripts', 'main_prog')
p = Process(main)
p.start()
p.join()
Upvotes: 0
Reputation: 3563
You could run a python command with Popen, for example:
Popen('python -c "from scripts.prog import main; main()"', shell=True)
Upvotes: 2