Can a "C++ application signal python script on completion"? - python

I'm working on developing a test automation framework. I need to start a process(a C++ application) on a remote linux host from a python script. I use the python module "paramiko" for this. However my c++ application takes sometime to run and complete the task assigned to it. So till the application completes processing, I cannot close the connection to the paramiko client. I wan thinking if I could do something like "the c++ application executing a callback(or some kind of signalling mechanism) and informing the script on completion of the task" Is there a way I can achieve this ?
I'm new to python, so any help would be much appreciated.
thanks!
Update: Is it not possible to have event.wait() and event.set() mechanism between the c++ application and the python script ? If yes, can somebody explain how it can be achieved ?
thanks in advance!

The best way I can think of to do this is to run both of them in a web server. Use something like Windows Web Services for C++ or a native CGI implementation and use that to signal the python script.
If that's not a possibility, you can use COM to create COM objects on both sides, one in Python, and one in C++ to handle your IPC, but that gets messy with all the marshalling of types and such.

Related

Simple way to communicate between CLI and native GUI in both windows and mac

We have a CLI application with business logic inside, written in python.
We want to build native GUI apps in both windows and mac, providing the funcionality of the CLI.
What is the best (easy, fast to implement) way to communicate (two-way) between the GUI app and the CLI communication, in a way that the extra code developed in the CLI will work with both windows and mac native apps? CLI and GUI apps will be on the same machine. Calls will be made to the CLI like uploading a file, and feedback will be returned to GUI, like progress, errors, etc.
Any solution is considered:
Sockets, Remote procedure calls, any other interprocess communication way, any other obvious(?) but missed solution.
Thank you!
Not a final answer, but there is a cross-platform IPC library with .NET and Python bindings, that is used by iPython called ZeroMQ. You may want to check that. http://zeromq.org/

Deploying a Python Script to Windows and Linux

I have a python server that I need to run in both a Linux and Windows environment, and my question is about deployment. What is the best method for deploying the solution instead of just double clicking on the file and running it?
Since I use the server_forever() on the server, I can just run the script from command line, but this keeps the python window open. If I log off the machine, naturally the process will stop. So what is the best method for deploying a python script that needs to keep running if the user is logged in or off a machine.
Since I am going to be using multiple environment, Linux and Windows, can you please be specific in what OS you are talking about?
For windows, I was thinking of running the script 'At Startup' using the Windows scheduler. But I wanted to see if anyone had a better option. For linux, I really don't know what to create. I am assuming a CRON job?
Deployment does refer to coding, so using serve_forever() on a multiprocessing job manager keeps the python window open upon execution. Is there a way to hide this window through code? Would you recommend using a conversion tool like py2exe instead?
This is the subject matter of a whole library of books, so I will just give an introduction here :-)
You can basically start scripts directly and then have multiple options to do this in a way that they keep running in the background.
If you have certain functionality that needs to run on regular moments, you would do this by scheduling it:
Windows: Windows Scheduler or specific scheduling tools
Linux: Cron
If your problem is that you want to start a script without it closing on you while SSH'ing into Linux, you want to look into the "screen" or "tmux" tools.
If you want to have it started automatically this could be done by using the "At Startup" as you point out and Linux has similar functionalities, but the preferred and more robust way would be to set up a service that is better integrated with the OS.
Windows: Windows Service
Linux: Daemon
Even more capabilities can be yielded by using an application server such a Django
Tomcat (see comment) is an option, but definitely not the standard one; you'll have a hard time finding support both from Tomcat people running Python or Python people running their stuff on Tomcat. That being said, I imagine you could enable CGI and have it run a Python command with your script.
Yet, instead of just starting a Python script I would strongly encourage you to have a look at different Python options that are probably available for your specific use case. From lightweight web solutions like Flask over a versatile networking engine like Twisted to a full blown web framework like Django.
They all have rather well-thought-out deployment solutions available. Look up WSGI for more background.

cgi scripts with no server

My goal is to use to make it easy for non-programmers to execute a Python script with fairly complex options, on a single local machine that I have access to. I'd like to use the browser (specifically Safari on OS X) as a poor man's GUI. A short script would process the form data and then send it on to the main program(s).
I have some basic examples of python scripts run using the built-in Apache server, by clicking submit on a form whose html is th:
e.g. here. What I want to do now is do it without the server, just getting the form to invoke the script in the same directory. Do I have to learn javascript or ...? I'd be grateful for any leads you have. Thanks.
It doesn't make sense -- what a browser does when it submits a form by definition is to make a request to a web server.
If all that's going on is that you don't want to be running Apache, you could hook something simple up using the CGIHTTPServer class that's provided as part of the Python Standard library.
If you don't want a server process at all, and you're using a suitably modern browser, you may want to look at using HTML5 local storage, but that's not a Python solution.
Well, there always has to be some kind of "server" involved to communicate over HTTP. You could have a python script listening on port 80 on your machine, that in turn runs the scripts specified with the form's action attribute.
You won't get away without some sort of server, I'm afraid.
PS: There are already a couple of good minimalistic python HTTP servers that would do the trick. Just google for it.
Regards, aefxx
Pyjamas Desktop will allow you to deploy a browser-based desktop application.

Safest python code running

How can I protect my web server, if I run custom users code on server. If any user can submit his python source on my server and run it.
Maybe some modules or linux tools for close any network and hardware activity for this script.
Thank's all for help!
The concept you're thinking of is sandboxing. Check out the Python wiki page about it:
http://wiki.python.org/moin/SandboxedPython
In general, python is not the best language choice if you want to allow the execution of untrusted code. The JVM and .NET have much better support for sandboxing, so Jython and IronPython would be better choices.

How do I use the quartz scheduler with Python?

Is there a guide or tutorial on how to use the quartz Scheduler with Python.
Is there an existing API for Python?
Given that Quartz is a Java application/library, the simplest thing to do may be to run it within Jython.
Failing that, and if you simply want to control the configuration of jobs from Python, perhaps the JDBC-JobStore is of use, and you could write jobs into the database via Python. You'll still need an instance of Quartz running in a JVM. However, I'm not sure how well supported that is as a scenario.
Finally, you may be able to talk to a running Quartz instance via JMX. You'll need a JMX client, and consequently you'll need to spawn off a Java JMX client from your Python process.
I think (regrettably) there's a non-trivial mismatch between a Quartz instance (in Java) and your Python code.

Categories

Resources