Ver código fonte

Fix broken spawning of chatwindow

Yentl Van Tendeloo 7 anos atrás
pai
commit
7fe599ba15
4 arquivos alterados com 24 adições e 8 exclusões
  1. 10 2
      classes/main_app.xml
  2. 1 1
      classes/window/activity.xml
  3. 10 4
      frontend.py
  4. 3 1
      run_chatwindow.py

+ 10 - 2
classes/main_app.xml

@@ -184,12 +184,14 @@
                                         # Interestingly, threads don't work well with SCCD, so this is a gamble.
                                         # On UNIX systems, a simple "select" statement would have sufficed in the SCCD condition, but Windows doesn't like elegant solutions...
                                         def enqueue_output(out, queue):
+                                            print("Waiting for output")
                                             for line in iter(out.readline, b''):
+                                                print("Getting input: " + str(line))
                                                 queue.append(line)
                                             out.close()
 
                                         self.output_queue = []
-                                        p = threading.Thread(target=enqueue_output, arguments=[self.subprocess.stdout, self.output_queue])
+                                        p = threading.Thread(target=enqueue_output, args=[self.subprocess.stdout, self.output_queue])
                                         p.daemon = True
                                         p.start()
                                     </script>
@@ -201,11 +203,17 @@
                                     <parameter name="value"/>
                                     <script>
                                         # Send data to the spawned subprocess
-                                        self.subprocess.stdin.write(value)
+                                        print("Write to stdin")
+                                        self.subprocess.stdin.write(value + "\n")
+                                        self.subprocess.stdin.flush()
+                                        print("Write OK")
                                     </script>
                                 </transition>
 
                                 <transition cond="self.output_queue" target=".">
+                                    <script>
+                                        print("Got output on stdout: " + self.output_queue[0])
+                                    </script>
                                     <raise event="mv_data_input">
                                         <parameter expr="self.output_queue.pop(0)"/>
                                         <parameter expr="None"/>

+ 1 - 1
classes/window/activity.xml

@@ -253,7 +253,7 @@
                         <transition event="mv_response" target="../processing">
                             <parameter name="taskname"/>
                             <script>
-                                self.subprocess = subprocess.Popen([sys.executable, sys.argv[0], "--address", data['mv_address'], "--username", data['username'], "--password", data['password'], "--taskname", taskname, "--spawn", "run_chatwindow.py"])
+                                self.subprocess = subprocess.Popen([sys.executable, sys.argv[0], "--address", data['mv_address'], "--username", data['username'], "--password", data['password'], "--taskname", taskname, "--spawn", "./run_chatwindow.py"])
                             </script>
                         </transition>
                     </state>

+ 10 - 4
frontend.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Wed Nov 15 10:17:38 2017
+Date:   Wed Nov 15 13:39:38 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   Modelverse Visual Editor - Tkinter Version 
@@ -543,21 +543,27 @@ class MainApp(RuntimeClassBase):
         # Interestingly, threads don't work well with SCCD, so this is a gamble.
         # On UNIX systems, a simple "select" statement would have sufficed in the SCCD condition, but Windows doesn't like elegant solutions...
         def enqueue_output(out, queue):
+            print("Waiting for output")
             for line in iter(out.readline, b''):
+                print("Getting input: " + str(line))
                 queue.append(line)
             out.close()
         
         self.output_queue = []
-        p = threading.Thread(target=enqueue_output, arguments=[self.subprocess.stdout, self.output_queue])
+        p = threading.Thread(target=enqueue_output, args=[self.subprocess.stdout, self.output_queue])
         p.daemon = True
         p.start()
     
     def _parallel_behaviour_init_modelverse_conversing_execute_SC_wait_subprocess_0_exec(self, parameters):
         value = parameters[0]
         # Send data to the spawned subprocess
-        self.subprocess.stdin.write(value)
+        print("Write to stdin")
+        self.subprocess.stdin.write(value + "\n")
+        self.subprocess.stdin.flush()
+        print("Write OK")
     
     def _parallel_behaviour_init_modelverse_conversing_execute_SC_wait_subprocess_1_exec(self, parameters):
+        print("Got output on stdout: " + self.output_queue[0])
         self.raiseInternalEvent(Event("mv_data_input", None, [self.output_queue.pop(0), None]))
     
     def _parallel_behaviour_init_modelverse_conversing_execute_SC_wait_subprocess_1_guard(self, parameters):
@@ -8264,7 +8270,7 @@ class ActivityExecutor(RuntimeClassBase, tk.Toplevel, SCCDWidget):
     
     def _all_all_execute_execute_0_exec(self, parameters):
         taskname = parameters[0]
-        self.subprocess = subprocess.Popen([sys.executable, sys.argv[0], "--address", data['mv_address'], "--username", data['username'], "--password", data['password'], "--taskname", taskname, "--spawn", "run_chatwindow.py"])
+        self.subprocess = subprocess.Popen([sys.executable, sys.argv[0], "--address", data['mv_address'], "--username", data['username'], "--password", data['password'], "--taskname", taskname, "--spawn", "./run_chatwindow.py"])
     
     def _all_all_execute_alter_context_result_check_next_0_guard(self, parameters):
         return self.exec_output_signature

+ 3 - 1
run_chatwindow.py

@@ -5,6 +5,7 @@ import chatwindow
 from sccd.runtime.statecharts_core import Event
 from sccd.runtime.tkinter_eventloop import *
 import threading
+import sys
 
 from sccd_widget import SCCDWidget
 
@@ -26,7 +27,8 @@ def stdin_poller(controller):
 def stdout_printer(controller):
     port = controller.addOutputListener("stdout_port")
     while 1:
-        print(port.fetch(-1).parameters[0])
+        sys.stdout.write(port.fetch(-1).parameters[0] + "\n")
+        sys.stdout.flush()
 
 input_thread = threading.Thread(target=stdin_poller, args=[controller])
 input_thread.daemon = True