Activiti: Shell Task freezes process when it used Python - python

Question about Activiti 5.17.0.
I'm researching to use external REST API and thought Shell Task with Python might be good solution. But it freezes the process in Activiti Explorer.
Is there any better way?
Read manual here: (Shell Task)
http://www.activiti.org/userguide/#bpmnShellTask
Found working sample:
https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/test/resources/org/activiti/examples/bpmn/shell/ShellTaskTest.testEchoShellWindows.bpmn20.xml
It works simple Windows command (ex. echo), but using Python freezes the process and browser.
It waits process done forever (or until timeout). Browser shows waiting icon and do not respond in Activiti Explorer.
It works as following:
OK: simple DOS command
OK: simple batch file
OK: batch file in batch file (note: don't use "call")
Followings are not working and causes freeze:
NG: python (even --version)
NG: batch file call python
NG: batch file call another batch file with "call" command
I've tried "wait" option (default=true) as false. Then process comes back, but there's no result value evaluated.
Is there any workaround or better solution to use external REST API from Activiti? Any advice is helpful.
Thank you,
Naoki

Related

Automation of Powershell script, that invokes a Python script, doesn't work (via Task Scheduler)

I am trying to create a bunch of automations on my PC with Windows, and I encountered some obstacles while trying to automate a Powershell script with Windows Task Scheduler.
Right now, I have managed to set up a Task Scheduler to perform an actual script, but despite the whole script working as intended when I start it manually, it doesn't work right while invoked via task scheduler.
The Powershell script is very simple, it is meant to invoke a certain Python script. I also created a log transcript for testing purposes.
python dataset_creator.py --to_import yes --to_export yes
Start-Transcript -Path "<path>\transcript0.txt"
While invoked manually, the Python script works, but via Task Scheduler, the only working part is a transcript creation (ergo - no Python script is running). The Task Scheduler informs me itself that the task executed properly. This is how I set up the action:
Program: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "C:\<path>\powershell_script.ps1"
As for now, I have set it on a SYSTEM account, I have tried to set it on my user admin account, but it doesn't work as well.
Could you suggest the potential issues? I scrolled through several articles and nothing works. I also tried to skip the Powershell part (aka - set up the task relying only on a Python task), but it didn't work so far, and I also initially wanted to insert a number of Python scripts invokations into a single Powershell file.
I am also open to some Windows Task Scheduler alternatives suggestions.

Running Python script as Executable

I have been attempting to run my python script as a service, and have followed the advice contained in several previous forum posts. However, these have not helped me thus far. Here is what I have attempted up until now:
Used an SMWinservice class that allowed me to install my Python script as a service. This solution, however, would not launch. If I would try to start it, I would receive an error message.
I have tried using NSSM with : nssm install myService pathToInterpreter PathToScript. Note, all files etc. can be found in the local directory of the PathToScript. For what its worth, I also tried using the GUI version of NSSM. When I rebooted my computer, it showed as "Paused" in task manager. I stopped it, and then tried to run it again, and I received an error. I have tried NSSM with both python.exe and pythonw.exe.
I suspect that a possible source of error is the fact that my program uses a text file as a configuration file. This configuration file has been coded as being in my local working directory. However, I wouldn't think this would be an issue with NSSM. I know for a fact that my program will completely exit, using the exit command, if the configuration file is not found.
I was thinking of doing a batch file and starting the batch file with the script and running it like that, but I prefer a service since it can monitor the process, can restart it, or windows can notify me via email if there is an issue with my service.
For completeness, I should also mention that the program runs without issue outside of a service. For the reason that the program runs as expected, I decided to not post the code, unless someone would like to see it for whatever reason.

Python script freezing program

I am new here but I recently have been messing around with python and Qt. My situation is that one of the scripts I call does a lot of OS commands and basically waits for a response. When I call this script it runs fine and acts accordingly except in my main program the screen is frozen until I exit out of the cmd. I think this is because mt script just waits there for a response, is there anyway to make it so that even though the script is running and executing(waiting for response with cmd) the user can still use other aspects of the main program?
As mentioned in comments, you will need to use threading. Threading allows multiple functions to executed at the same time. Check out this link Python threading.
You'll just have to run your side script on a different thread.

Python cron job under windows7

I have created a simple cron job under windows to run a very simple python scrape:
scrape webpage
store data into csv file
close file
Cron job under Windows worked fine-without any probs. All of sudden, that cron job stopped working, my output file is not getting updated. When I run the scrape manually (double click on python file or via python IDE) I would typically get my debug output "everything ok" in a windows dialog window and the target file gets updated. During the cron job I can see that debug output window popping up and printing the same "everything ok" debug, but the file is just not getting updated.
I tried rebooting my machine, close/open all program. Created a new task in the scheduler, it still wouldn't work. Any suggestions?
Thanks
Peter
After playing around with all potential settings in windows and many wasted hours I found a workaround.
My initial setup in the task manager was calling the python.exe and my python.py file was passed as an argument. Just as described here: http://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/. The difference at the end that made my cron job work again was that I deleted passing the python file as an argument and now calling python file directly. Not sure why the initial setup stopped working - but this has helped. Hope you don't get into the same time wasting situation.

End Python Script when running it as boot script?

I am using Debian and I have a python script that I would like to run during rc.local so that it will run on boot. I already have it working with a test file that is meant to run and terminate.
The problem is that this file should eventually run indefinitely using Scheduler. It's job is to do serial reads, a small amount of processing on those reads, and inserts into a MySQL database. However, I am nervous about then not being able to cancel the script to get to my login prompt if changes need to be made since I was unable to terminate the test script early using Ctrl+C (^C).
My hope is that there is some command that I am just missing that will accomplish this. Is there another key command that I'm missing that will terminate the python script and end rc.local?
Thanks.
EDIT: Another possible solution that would help me here is if there is a way to start a python script in the background during boot. So it would start the script and then allow login while continuing to run the script in the background.
I'm starting to think this isn't something that's possible to accomplish so other suggestions to accomplish something similar to what I'm trying to do would be helpful as well.
Thanks again.
Seems like it was just a dumb mistake on my part.
I realized the whole point of this was to allow the python script to run as a background process during boot so I added the " &" to the end of the script call like you would when running it from the shell and viola I can get to my password prompt by pressing "Enter".
I wanted to put this answer here just in case this would be something horribly wrong to do, but it accomplishes what I was looking for.
Making scripts run at boot time with Debian
Put your script in /etc/init.d/. So, if your script is in a file called my_script, it should be located at /etc/init.d/my_script.
Run update-rc.d my_script defaults as root.
Don't forget to make your script executable and include the shebang. That means the first line of the script should be #!/usr/bin/python.

Categories