When will train() method in easy_seq2seq stop? - python

I'm running a RNN demo at https://github.com/suriyadeepan/easy_seq2seq/blob/master/execute.py, everything runs soomthly except I don't know when should it stop.
The train() method in this module (exectue.py) doesn't seem have stop condition. Anyone else has ever run this demo too? How can this method stop? Kill it by yourself? If so, when?
Thanks for help.

The train() method will not stop on it's own, as it contains an infinite-loop. The train() method periodically saves the model after a certain number of iterations, depending on the settings in seq2seq.ini.
You should cancel the training when you are ready (with CTRL + C). You can then run the most-recently saved model in 'test' or 'serve' mode. You can change the mode in seq2seq.ini and then run python execute.py again to run the code in that mode.

Related

Python - attaching to project half way thru the execution

Google'd but only getting results about how we can create launch.json configs and start the debugging from line #1.
So I have a [big?] Python project that runs from command-line, and I just created a helper method (def pauseHereAndNotifyUserOnSlack(user=<username>) to pause where needed and wait for the user to press a key to exit out of this [infinite] loop and resume the code.
I am wondering if there's a way to attach my python project while the code is paused, inspect the variables and stuff, and resume execution from there?
(Think C#/C++ has this feature, where they attach using symbols and stuff? Not 100% sure how this works. Maybe I am confusing myself?)
Let me know if you guys need more clarification. TIA
You don't need to debug your code from line 1, set breakpoints in your code and start debugging from there and inspect variables and can also resume execution from there. (if this is what you were talking about)
the play button can be used to resume your execution.

How to wait until os.system() executes?

I am using os.system() to execute the first commend mentioned here. It essentially trains a fasttext supervised model with autotune enabled. But important thing is that, the program flow continues to next line before train completes and also before saving the model file. Both the training and model file saving happen with this single command.
So, basically I want to prevent the program to move to the next line until the commend executes, how to achieve it?

How to interactively (e.g. using the terminal) intervene a for loop

I'm training my DQN and it often happens that I want to change a setting in the middle of the training. I know there is the option to terminate the running code via the terminal with CTRL+C but I'd like to intervene only after the currently running epoch has finished. Is there a way to implement that. (I'm using VS-Code)
You could insert a input() after every epoch and use this.. But that means that you have to sit in front of the computer the whole execution time to make the program execute without long pauses

Python threading script execution in Flask Backend

Currently i'm trying to use proper threading to execute a bunch of scripts.
They are sorted like that:
Main Thread (Runs the Flask app)
-Analysis Thread (Runs the analysis script which invokes all needed scripts)
-3 different functions executed as thread (Divided in 3 parts so the analysis runs quicker)
My problem is i have a global variable with the analysis thread to be able to determine after the call wether the thread is running or not. The first time it does start and running just fine. Then you can call that endpoint as often as you like it wont do anything because i return a 423 to state that the thread (the analysis) is still running. After all scripts are finished, the if clause with analysis_thread.isAlive() returns false as it should and tries to start the analysis again with analysis_thread.start() but that doesn't work, it throws an exception saying the thread is already active and can't be started twice.
Is there a way to achieve that the script can be started and while it is running it returns another code but when it is finished i can start it again ?
Thanks for reading and for all your help
Christoph
The now hopefully working solution is to never stop the thread and just let it wait.
in the analysis script i have a global variable which indicates the status it is set to False by default.
inside the function it runs two whiles:
while True:
while not thread_status:
time.sleep(30)
execution of the other scripts.
thread_status = False # to ensure the execution runs just once.
I then just set the flag to True from the Controller class so it starts executing

Passing values between thread.timer runs

I'm scratching my head here, not sure if this is the right way to approach it but as of right now I can't think of another way(open to suggestions). So I am running the BACpypes library, which requires you to create a device, application then call the run() which initiates the the device on the network.
What I am trying to do is send a write_property command to the device every couple of minutes but the problem is I can only do so after i call the run() method(which initializes and hosts the device), which as soon as I do, nothing beyond that method gets called until I stop the program completely because it's a single threaded application
So I thought I'd create a method called Update which will run every 30 seconds and try and write to the device using thread.Timer(since it then runs on a seperate thread). The issue I'm having is that the Update method I use to write to the device can't be executed until I run the run() command, but I have to execute my method before the run() command otherwise it will never execute. Basically what I want to know is can I send a bool to my Update method that will prevent it from running the write_property the first time so that it can wait till run() has been executed, then every time after that it can try to write to it? Perhaps just add a try/catch and skip ?
example of what the code looks like: (this is my main try block)
isFirstRun = False
try:
test_device = LocalDeviceObject(...)
this_application = Application(test_device, args.ini.address)
Update(None,this_application, isFirstRun)
run()
Update method:
def Update(client, app, isFirstRun):
threading.Timer(30.0, Update, [client,app, isFirstRun]).start()
if the run() method hasnt been called yet
skip
else if it has
execute rest of code
Instead of calling Update directly, why not call threading.Timer(...) in your main thread as well? That way Update won't be run initially until after 30 seconds have passed which appears to be the same as what you are doing with a the booleans, but a lot less clunky.

Categories