You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 1.9KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from subprocess import *
  2. from threading import Thread
  3. import time
  4. class Modell(Thread):
  5. def __init__(self):
  6. Thread.__init__(self)
  7. self.aktiv= True
  8. self.aktiv2 = True
  9. def stop(self):
  10. print("stop thread")
  11. self.aktiv = False
  12. def setFunktion(self, func, args=None, kwargs=None):
  13. self.func = func
  14. self.args = args or []
  15. self.kwargs = kwargs or {}
  16. def run(self):
  17. print("start thread")
  18. #self.aktiv = True
  19. t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
  20. t.setDaemon(True)
  21. t.start()
  22. while self.aktiv:
  23. time.sleep(0.1)
  24. def counter(self):
  25. n = 0
  26. while self.aktiv2:
  27. print(n)
  28. time.sleep(0.1)
  29. n = n+1
  30. if not self.aktiv2:
  31. print("stop")
  32. break
  33. def stop2(self):
  34. self.aktiv2 = False
  35. #self.aktiv = False
  36. def test(self):
  37. command = ["bash", "meta/dist/Release/openvibe-designer.sh", "--play", "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/p300-visual-1-acquisition.xml", "--no-gui"]
  38. process = Popen(command, stdout=PIPE, universal_newlines=True)
  39. while self.aktiv2:
  40. output = process.stdout.readline()
  41. print(output.strip())
  42. x = output.find("Application terminated")
  43. y = output.find("Error")
  44. z = output.find("Initialization")
  45. if(x != -1):
  46. print("Training finished")
  47. process.terminate()
  48. break
  49. elif(y != -1 ):
  50. process.terminate()
  51. break
  52. if not self.aktiv:
  53. print("stop")
  54. break
  55. m = Modell()
  56. m.setFunktion(m.test)
  57. m.start()
  58. time.sleep(2)
  59. m.stop()
  60. m.join()
  61. while True:
  62. pass