I suspect it's something to do with UWsgi doing funky things with fork and subprocesses. For example https://stackoverflow.com/questions/17592692/running-a-subprocess-in-uwsgi-application .
On Tue, Mar 3, 2020 at 12:37 PM Emerson Barea <[email protected]> wrote: > Hi Michael, thanks for your reply. I'm sorry I didn't confirm it earlier, > but I've been quite sick this past week. > > Well, I tried to follow the suggestion you made, making the following > changes: > > scripts/tests.py > > def main(argv): > <my code here> > > > if __name__ == '__main__': > main(argv=sys.argv[1:]) > > > > my view code: > > arguments = ['--config_file=minisecbgp.ini', > '--execution_type=create_node', > '--hostname=%s' % form.node.data, > '--username=%s' % form.username.data, > '--password=%s' % form.password.data] > #subprocess.Popen(['tests'] + arguments) > subprocess.Popen([sys.executable, '-m', 'minisecbgp.scripts.tests'] + > arguments) > > > and now I receive this erro when I try to execute the view in browser: > > Mar 3 15:24:57 lpttch uwsgi[7284]: /home/tocha/Documentos/projetos/ > MiniSecBGP/venv/bin/uwsgi: unrecognized option > '--config_file=minisecbgp.ini' > Mar 3 15:24:57 lpttch uwsgi[7284]: getopt_long() error > > I tried to modify the setyp.py console_scripts to > > 'tests = minisecbgp.scripts.tests' > > or removing this entry_point, since the call to the script is being made > directly now, but I always got the same error. > > Please, do you known what I'm doing wrong? > > Thank you. > > Emerson > > > Em quinta-feira, 27 de fevereiro de 2020 21:28:04 UTC-3, Michael Merickel > escreveu: > >> Your environment isn't modifying the env PATH, which is what Popen is >> relying on to find the script. >> >> It'd be better not rely on the PATH and instead just run the code using >> `python -m foo`, but that doesn't actually work with console scripts. You >> would instead do `subprocess.Popen([sys.executable, '-m', >> 'minisecbgp.scripts.config'] + arguments)`. You'd then need to define an >> `if __name__ == '__main__': main()` in your script instead of relying on >> the console script to invoke your main function. >> >> Alternatively fix your PATH, but I find that less ideal because it can >> change per-environment where the console scripts are actually installed. >> >> - Michael >> >> On Thu, Feb 27, 2020 at 5:41 PM Emerson Barea <[email protected]> >> wrote: >> >>> Hi there. >>> >>> My application has some scripts on .app.scripts (.app.scripts.tests and >>> .app.scripts.config). >>> >>> I configured this scripts in setup.py file like this: >>> >>> entry_points={ >>> 'paste.app_factory': [ >>> 'main = minisecbgp:main' >>> ], >>> 'console_scripts': [ >>> 'initialize_minisecbgp_db = minisecbgp.scripts.initialize_db:main', >>> 'tests = minisecbgp.scripts.tests:main', >>> 'validate_hostname = minisecbgp.scripts.validate_hostname:main', >>> 'config = minisecbgp.scripts.config:main', >>> ], >>> >>> >>> I call these two scripts in my view with the code below: >>> >>> arguments = ['--config_file=minisecbgp.ini', >>> '--hostname=%s' % form.node.data, >>> '--username=%s' % form.username.data, >>> '--password=%s' % form.password.data] >>> subprocess.Popen(['config'] + arguments) >>> >>> >>> and, when I run my application with the commands below, everything >>> works well. The page works fine and the scripts tests and config works well. >>> >>> pip install -e ".[testing]" >>> pserve minisecbgp.ini --reload >>> >>> >>> So, I want to put my app in production, and I'm trying to use uwsgi and >>> nginx to do it. When I configured uwsgi and nginx and open the app in >>> browser, the app works well, but when I call the view that executes the >>> scripts tests and config, I receave a 502 bad gateway error. Looking at >>> syslog file, I receaved this error: >>> >>> Feb 27 20:12:56 lpttch uwsgi[14110]: subprocess.Popen(['tests'] + >>> arguments) >>> Feb 27 20:12:56 lpttch uwsgi[14110]: File >>> "/usr/lib/python3.6/subprocess.py", line 729, in __init__ >>> Feb 27 20:12:56 lpttch uwsgi[14110]: restore_signals, >>> start_new_session) >>> Feb 27 20:12:56 lpttch uwsgi[14110]: File >>> "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child >>> Feb 27 20:12:56 lpttch uwsgi[14110]: raise child_exception_type( >>> errno_num, err_msg, err_filename) >>> Feb 27 20:12:56 lpttch uwsgi[14110]: FileNotFoundError: [Errno 2] No >>> such file or directory: 'tests': 'tests' >>> >>> Please, can somebody help me? >>> >>> Emerson >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "pylons-discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/pylons-discuss/9a78ebba-f50d-4143-9fea-550d3bce9e1e%40googlegroups.com >>> <https://groups.google.com/d/msgid/pylons-discuss/9a78ebba-f50d-4143-9fea-550d3bce9e1e%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> Michael >> > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/5cc6641f-ffe2-4b16-b26f-99edf01865f8%40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/5cc6641f-ffe2-4b16-b26f-99edf01865f8%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Michael -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwEcdZ2Y%2BCRAHxjGEfyZCtS3fKPN55qJNJswpNYTvNCQbw%40mail.gmail.com.
