Author Topic: Can I kill a previous called script (PY.ExecFile)  (Read 3099 times)

0 Members and 1 Guest are viewing this topic.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Can I kill a previous called script (PY.ExecFile)
« on: June 26, 2015, 05:25:24 PM »
I'm developing some complex code using Python. This python script is called with PY.ExecFile on VC startup so I can use the functions further with PY.ExecString.
This is a wonderful feature IMO which adds unlimited power to the already powerful VC.

Sometimes I would like to kill the script so I can test a modification or a correction that I just made. Since it stays in memory, the only way I know to do this is to perform a full restart of VC.

I tried using the reinitialize python command from the Python editor, but it seems the threads which have been started by the script still remain running.
Is this correct or I'm doing something wrong?
Is there a quicker way to force killing or restarting a specific python scripts?

Sorry if I'm being stupid somehow... Thank you.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Can I kill a previous called script (PY.ExecFile)
« Reply #1 on: June 27, 2015, 10:07:19 AM »
You are doing what you are supposed to. Reinitializing was created for this purpose, but spawned threads seem to survive even after the entire Iron Python object is destroyed and recreated.

I will take another look to see if there is anything I can do, but for now you'll need to either keep restarting VC or actually keep all your threads in a list or something so you can call a function to kill them all yourself.

For what it's worth, I've been restarting VC over and over again myself when in this situation.
« Last Edit: June 27, 2015, 11:08:00 AM by nime5ter »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Can I kill a previous called script (PY.ExecFile)
« Reply #2 on: June 27, 2015, 11:29:58 AM »
I just banged my head against this one (again) for about 1.5 hours.  I am not able to find a direct solution.

However, I can propose a sort of workaround.

I will make a small change to the "Reinitialize Python" function so that it sets a variable named killPy to true.

Any thread that is running forever will probably look a little bit like this:

Code: [Select]
while 1:
        try:
            ...
            ...
       
        except:

change it to look like this and it should stop looping when you reset the python engine:
Code: [Select]
while not killPy:
        try:
            ...
            ...
       
        except:

I know it is not perfect but it will have to do, and in situations where it does not work then we will just have to restart VC.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Can I kill a previous called script (PY.ExecFile)
« Reply #3 on: June 27, 2015, 12:11:24 PM »
Thanks James! The workaround seems more than enough.
Is it coming on the next release already? Perhaps tomorrow?

Just kidding!  :bonk
no hurry!

You guys are fast with your support!
Thanks!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Can I kill a previous called script (PY.ExecFile)
« Reply #4 on: June 27, 2015, 01:06:01 PM »
I am actually planning to release a bug-fix version soon anyway, so hopefully within a day or two.  ;D

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando