Author Topic: Long Delays without voxcommando freezing  (Read 2800 times)

0 Members and 2 Guests are viewing this topic.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Long Delays without voxcommando freezing
« on: March 21, 2013, 03:25:46 PM »
Hi James

A much needed feature VC.Pause without voxcommando freezing, my creativity takes a serious blow :bonk when it comes to not having a VC.Pause without the VC freeze.
VC.TriggerEvent is a no no :(.
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Long Delays without voxcommando freezing
« Reply #1 on: March 21, 2013, 05:30:49 PM »
It is not going to happen.

What do you mean VC.TriggerEvent is a no no?

edit:  OK, I should not say that it absolutely won't happen, but it is sticky business and I'm not keen to get gummed up in it!  It involves running each command in it's own thread, which by itself is not such a big deal, but as soon as that command starts to touch other parts of the program, there is a great potential for crash-tastic results.
« Last Edit: March 21, 2013, 06:45:25 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Long Delays without voxcommando freezing
« Reply #2 on: March 21, 2013, 05:49:10 PM »
maybe your needs can be met using the new python plugin.  Multithreading is supported so you could launch a new thread that pauses for a certain amount of time before triggering other actions and events?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Long Delays without voxcommando freezing
« Reply #3 on: March 22, 2013, 11:55:34 AM »
here's an example to get you started:

Code: [Select]
import threading
import datetime
import time       

class ThreadClass(threading.Thread):
    def run(self):
        time.sleep(1)
        osd("it has been 1 second")
        time.sleep(1)
        osd("it has now been 2 seconds")
        time.sleep(3)
        osd("it has now been 5 seconds")

def osd(msg="test"):   
    #show text at top for 1.5 seconds
    vc.callAction("OSD.ShowText",msg+"&&1000&&-30", None)


osd("let's go...")
t = ThreadClass()
t.start()

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Long Delays without voxcommando freezing
« Reply #4 on: March 22, 2013, 02:38:35 PM »
Thanks for the example.
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Long Delays without voxcommando freezing
« Reply #5 on: March 22, 2013, 03:16:57 PM »
You can try this. Use the contents of the attached to update an existing install of VC by overwriting the old files.

This is a test release that allows for mult-ithreaded commands.  Use this at your own risk!

How it works...

by default all commands should still operate normally, meaning that a VC.Pause action will freeze VC and no other commands can start until the current command finishes.  This should be OK for the majority of cases.  But if you absolutely must have it...

Name of your commands so they begin with ++ (see the example xml below).  Any commands whose name starts with ++ will be run in it's own thread.  Be careful with this and only use it if you really need to.  If weird stuff starts to happen, don't be too surprised.  Be particularly careful with commands that read and write {LastResult}.  Since commands may be running simultaneously, you might not get what you expect!

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="thread test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="27" name="++test this thread 1" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.TellVox</cmdType>
      <cmdString>test this thread 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 1</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 3</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>test this thread 1</phrase>
  </command>
  <command id="39" name="++test this thread 2" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 1</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>1700</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 3</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>test this thread 2</phrase>
  </command>
  <command id="56" name="do something else" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>OK.</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>do something else</phrase>
  </command>
</commandGroup>

You should be able to say "test this thread 1", and then while it is running (it will also call yet another command on another thread by using tellvox), you can say "do something else".  You will have 3 commands running at once.

If time starts to run backwards or things start falling upwards, don't say you weren't warned...  :biglaugh

[Attachment deleted. This is now standard in VC. Preface your command name with ++ to have the command run in its own thread. Note: if you don't understand what we mean by this then use with caution or not at all. Do not overdo it, regardless.]
« Last Edit: February 13, 2015, 04:02:04 PM by nime5ter »

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Long Delays without voxcommando freezing
« Reply #6 on: March 23, 2013, 08:57:35 PM »
hi James

Problem wiih the osd example,  I'm using vc 0.986.
Once the python script finishes, the osd remains on the screen until i restart voxcommando, any idea why ?

[attachment=1]
« Last Edit: March 23, 2013, 08:59:48 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Long Delays without voxcommando freezing
« Reply #7 on: March 23, 2013, 08:58:41 PM »
Yes it is a side effect of multithreading.  But the update should solve it.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Long Delays without voxcommando freezing
« Reply #8 on: March 23, 2013, 09:01:58 PM »
I'll try the update, thanks again.
« Last Edit: March 23, 2013, 09:07:15 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Long Delays without voxcommando freezing
« Reply #9 on: March 23, 2013, 09:08:05 PM »
Problem solved with vc 0.987.
Neural Net Based Artificial Intelligence.