Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call binary executable from Python web application [closed]

I'm writing a web application using the flask python framework. As part of some of its functionality, it'll need to run some compiled programs (C++ code, but I have only access to the binaries) that does something (takes some files uploaded by users, processes them and produces some output files.)
What is the best way to architect such an application? There are no libraries or APIs to this code.

I can use the subprocess module to run this binary every time I need it but I'm worried about what might happen if the server gets too many requests (the process is CPU intensive). I guess I could set a limit on the number of concurrent requests it can handle. Are there any better solutions?

(Just out of curiosity, say I had the CPP source code, how could I go go about building a web application using this code?)

like image 719
qweert Avatar asked Mar 15 '26 05:03

qweert


1 Answers

My immediate suggestions would be these:

  1. Firstly, using a binary through system call probably would work to some extent though is a blackbox and as you've mentioned you could quite easily run into problems. You always have the possibility of processing the return value of the system call but again this isn't ideal, so wrapping in a simple API would probably only provide limited usefulness. My direct suggestion would be don't go with this option and try to compile it for your needs with one of the following ideas.

  2. If you have access to the source code; create a python extension module that allows you to interface with native C++ code. The given link can explain better than myself but it could be a fairly painless way to integrate your code in a way that doesn't require to launch from a binary as you've mentioned.

  3. Furthermore, to build a native web application for C++ code I'd turn you towards the Wt C++ web toolkit . This is a Qt styled framework that lets you build interactive web pages with native C++ and execute the binary to run a web-server and create a fully fledged website. As mentioned before, check the link and you'll get a better idea of what I'm talking about. There are probably other frameworks but I've used this and found it very straight forward.

like image 82
Alex Jones Avatar answered Mar 16 '26 18:03

Alex Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!