Launch on event with python - subprocess

here I write my first question as programming beginner starting with python.
I have a small script that executes a loop, which function is to download a list from the server, compare it with other lists and see if something has happened. Usually the answer is NO, but sometimes something happens. When the answer becomes YES, I would like this script at this point to be able to "launch the second program", a similar script that from here takes care of the instructions to handle the specific event signaled while the " main program "continues to interrogate the server and compare the answers (that's the only thing he has to do).
considering that you can run it with two clicks from the desktop specifying only one variable (that comes from the first script), I thought it was easy to "trigger" the execution of a python file in a new window or something like that ...can anybody tell me how I can make it start at the request of the first script avoiding that the first script remains blocked waiting for answers and continues to execute its cycle?

Related

Run each hotkey in a script file in a separate thread (with max threads per hotkey = 1)

I have a .ahk script file with 3 hotkeys.
Each hotkey takes a few seconds to complete.
What happens when I run hotkey a and then hotkey b before a is finished is that a is interrupted and the script continues with b.
Basically I want a and b to run concurrently.
Can I achieve this ?
True Multi-Threading in a single script does not exist (yet) in AutoHotkey.
While there are some ways to try and create "fake" multithreading, the best solution at the present is to have each hotkey run their own separate ahk script files using the Run command.
Hope this was helpful; if you would like an example of what this kind of code would look like, lmk and I can go ahead and create one.
When I need two functions to operate simultaneously I make multiple scripts that interact with each other. Unfortunately Autohotkey doesn't support multi-threading so that's the only way to do it.
Some ideas:
You can pass variables between scripts using msgbox and/or GUIs.
You can also use msgbox as a "wait until" if you need one function to
wait for the other to complete a part of automation.
I sometimes use that to make two scripts "play tag" to utilize all
the down time that exists during load times on websites. In other
words, I make two bots that interact with separate websites...
automating one while the other one is waiting for its page to load.
I have also utilized a "control panel" type of setup where I make a
master script that controls subroutines (other scripts) via GUIs. You
can then use the buttons to trigger Run commands and provide kill
buttons for each subroutine. This will give it the feeling of a full
application if you do it all through controlsend to a hidden gui. The
master script can then keep track of all the variables that need to
be exchanged between subroutines with msgbox like I mentioned before.
But I think at that point you might want to just incorporate another
more powerful language like python or Java.

Changing Code At Runtime While Debugging

I am using Eclipse Kepler Service Release 2 , EPIC 0.5.46 and Strawberry Perl 5 version 18 for perl programming. For debugging I am using Eclipse debugger and PadWalker .
I have an interactive perl program that writes to files based on answers provided by the users to multiple prompts. While debugging , every time i change a single line of code I have to rerun the whole program again and provide inputs to every prompt , which is really time consuming.
Is there a way to make changes to the code in a sub routine , in the middle of debugging session such that the instruction pointer resets itself to the first line of that sub routine. This way i do not have to restart the session to recompile the new code.
Appreciate your inputs and suggestions. Thank You!!!
What you want to do can be done, and I've done it many times in Perl myself. For example, see this.
However although what you describe may work (and is a bit dangerous), the way it is generally done a bit different and safer.
First one has to assume a regular kind of command structure like a command processor, or say a web server.
In a command processor or web server, you read a command (or get a web request), perform an action, then read another command, perform another action and so on. From your description, it sounds like you have such a structure.
In my case, I have each debugger command stored as in Perl file. This is helpful not only for facilitating this task, but also for understanding, testing and changing the code.
Given this kind of program structure, instead of trying to change the program counter, you complete the command and at the level where you are about to read a new command, you make the change and then reload the file which changes the code.
The specific Perl construct to do this is called do. Don't use require or use which will load in a Perl file only if that file or module hasn't been previously loaded. In your situation, you want to reload even if it has been loaded before.
So now how do you get to be able to issue a do command? As you suggest, you could do it through a debugger. Assuming you have this overall program stucture as described above, you put the breakpoint somewhere a common point in the caller which loops over things to process, rather than try to change things in indvidual commands.
And you don't even need a debugger to do this! Many web frameworks like Ruby on Rails, have a "development" mode where they save timestamps on files that implement functionality. If the file has changed they issue the "do" command before running the request.

Can I enter the debugger by sending an interrupt/signal? [duplicate]

This question already has answers here:
Stop and continue execution from debugger possible?
(6 answers)
Closed 9 years ago.
Ctrl+C interrupts a program. If I have dbstop on error set to true, this will put me in the debugger, because an interruption is treated as an error. However, the program is still interrupted; I can not continue it.
If I have a Matlab program running, is it possible after it has started to enter the debugger without triggering an error? To achieve the effect that a breakpoint would normally have, so either to add a breakpoint for an already running program, or tell it 'break wherever you are right now'.
Is this possible?
Not easily..
As suggested in the answer for the question that was linked as a dup, you can create certain conditions outside the MATLAB environment that the MATLAB code can check for. Since MATLAB is more or less single threaded, it makes doing things like that reallly challenging.
The Better Way: (I think/Hope)
I have not tried this yet, but I am almost positive you are able to edit uicontrols even while code is running because that IS on a different "thread" of sorts. For example, you can check a checkbox even while your code is running. If you were to include in your code something that checks for this checkbox value to be a 1, and if it is a 1, enter debug mode, I think that would work for you.
The good things about this is that everything stays in MATLAB and you don't need to do things like create a file to debug. The bad thing is you still need to add extra code to check which sometimes isn't feasible.
Hope this will work for you.

Passing an object as a parameter to a command

I Have two commands in my eclipse plugin. (Upload and Run). They can be invoked by the user one after another. So it only makes sense to invoke Run after the upload command is done.
Since the upload command possibly takes some time it will schedule a WorkspaceJob for actual execution. And returns right after it scheduled the job.
What i like to do know is to add another command called "Upload and Run" which (suprisingly) is supposed to first upload and then run the selection. Therefore it must be notified when the WorkspaceJob started in the Upload command has finished.
So i'd like to parameterize the command with an additional IJobChangeListener which it will add when the WorkspaceJob is scheduled.
Unfortunately it seems to me like it's only possible to pass Strings as parameters to a command or Objects that can be converted to Strings easily. However a Listener like this cannot be passed as a String.
How can i provide the command with such an Listener Object?
Is there maybe an other way of providing the Listener Object to the Command (other than passing it as a prameter) that i didn't think of?
Since your "Upload and Run" action is going to start the upload, you could then just schedule another job for the Run-action which simply calls join() on the workspace job-reference you have before doing anything else.
Update:
I think you're running into a limitation of the framework there. The commands are intended as an abstraction on the user-interface, not as an abstraction of getting things done. I'd simply go with reusing the Java code that you have, and directly invoke the code for both actions from the button for the joint functionality.

Making and Interfacing with Custom Services

I've been searching for this for awhile now, and I am not sure if I am just not using the correct search terms or if the answer is really that hard to find.
What I am trying to do is to create a new Windows service for a game server from a batch file, and then have a task run another batch file every 30 minutes or more that would run two commands on the game server's command line and do some file work.
Specifically, I am running a Minecraft server using Bukkit for a gaming community I help run, and I want to make sure that the thing is always up unless I specifically tell it to stop (like a service). Bukkit is run directly from a batch file and has it's own command line thing running on it.
I am told that you CAN run this type of thing as a service, but the command line will be hidden from view and/or interaction. This is the second part of my query. I have a handy little backup.bat file that copies all the world files and userdata files into a backup directory, 7zips it, and deletes the directory. The only thing is, is that Minecraft likes to always have the worlds' region files open and writing at all times, meaning that it could cause map corruption if I just run it straight off. To compensate, I need to run the command "save-off" on the server to disable the file hooks temporarily, run the backup, and as soon as it finishes, run "save-on" so that the game can continue without lost data.
What I would like to know about this second one is, is it possible to interface with the game service through a batch file, or do I need to create an application to do that? If the latter, how exactly does one go about doing that? I have moderate C++ knowledge (up through my second OO-C++ course in college), and can possibly learn another language if absolutely necessary.
So, in short, two questions:
1. Is it possible to, and how to run a BAT file as a Windows Service?
2. How to interface with said service via BAT files, and if not possible, what kind of application do I need to write (redirection to or writing a tutorial works for me).
Thank you in advance for any and all help!
Old question, user account doesn't seem active on SO anymore, but hey, if you stumble upon this because you have a similar problem:
Since we are speaking about a Bukkit Minecraft server, turn to the "Essentials" plugin for Bukkit.
It now includes a Backup function that does exactly what the OP asks for, namely stop the save so the files can be manipulated without corruption, launch a script, then starts again.
The script can be a backup one (examples provided in the linked page) but can be used to run any operation on the world's files.