Hi Lansana,
On 01/05/2020 01.21, Lansana Sangare wrote:
>
> Good evening here is the output on the developpement server and the code
> in django, for smaller scripts I get the output, but for larger ones I
> get strange output or sometimes not. In the attachment I have the large
> file run.py that I run in my django app. I ask for help if someone
> already has experience with it.
>
Some thoughts.
You are collecting all the output from stdout into the out object
returned from the the subprocess run() function.
That means the run function is buffering stdout before returning from
the call. I haven't been able to find a limit on the buffer size (which
could explain why it never returns), but even if there is no limit, you
most likely want to return the output in chunks to improve user
experience and limit memory usage.
Try to look at popen and use that instead:
https://docs.python.org/3/library/subprocess.html
The strange output is caused by combining the output from stdout and
stderr. You almost certainly don't want to return output from stderr to
the user, but consider that an error/exception and handle that
internally. The popen object should help you with that. If the script
you are calling is well written, it will return a non-successful return
code (ie. not 0) on errors which should cause an exception you can handle.
Finally, you are passing user input directly from the user (the "param"
POST value) to the script. As long as you don't execute it through the
shell, it is probably not much of a security issue, but be careful and
assume that the inp variable could contain anything and is not under
your control.
Hope that can help you in the right direction. I don't have any complete
solution, but that's what I would look into.
Kind regards,
Kasper Laudrup
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b457529a-4b16-3c78-e8ee-535fe9d1c0d7%40stacktrace.dk.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment