Skip to content

Commit

Permalink
FIX: add event wait
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed Feb 3, 2024
1 parent b532ba9 commit 140c158
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions GH/PyGH/scriptsyncGH_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self,
self.client_socket = socket
self.is_connected = False
self.connect_refresh_rate = 2 # seconds
self.msg_send_refresh_rate = 1 # seconds
self.msg_send_refresh_rate = 0.3 # seconds

self.queue_msg = queue_msg
self.lock_queue_msg = lock_queue_msg
Expand All @@ -141,6 +141,9 @@ def run(self):
self.connect_to_vscode_server()
self.clear_component()
self.expire_component_solution() # <<<< this is not good
continue

self.event_fire_msg.wait()

with self.lock_queue_msg:
if self.queue_msg is not None:
Expand All @@ -151,8 +154,6 @@ def run(self):
self.event_fire_msg.clear()
self.client_socket.send(msg.encode())

time.sleep(self.msg_send_refresh_rate)

except Exception as e:
if e.winerror == 10054:
# Connection was forcibly closed by the vscode-server
Expand All @@ -177,8 +178,10 @@ def connect_to_vscode_server(self):
break
except ConnectionRefusedError:
self.add_runtime_warning("script-sync::Connection refused by the vscode-server")
self.is_connected = False
except ConnectionResetError:
self.add_runtime_warning("script-sync::Connection was forcibly closed by the vscode-server")
self.is_connected = False
except socket.error as e:
if e.winerror == 10056:
self.add_runtime_warning(f"script-sync::A connect request was made on an already connected socket")
Expand Down Expand Up @@ -268,6 +271,7 @@ def safe_exec(self, path, globals, locals):
exec(code, globals, locals)
locals["stdout"] = output.getvalue()


# send the msg to the vscode server
self.queue_msg.put(output.getvalue())
self.event_fire_msg.set()
Expand All @@ -283,7 +287,7 @@ def safe_exec(self, path, globals, locals):

sys.stdout = sys.__stdout__
return locals

except Exception as e:

# send the error to the vscode server
Expand All @@ -296,7 +300,7 @@ def safe_exec(self, path, globals, locals):
raise Exception(err_msg)


def RunScript(self):
def RunScript(self, x):
""" This method is called whenever the component has to be recalculated. """
self.is_success = False

Expand All @@ -313,6 +317,7 @@ def RunScript(self):
).start()

# check the file is path
# TODO: menu item to add to set file
self.path = r"F:\script-sync\GH\PyGH\test\runner_script.py" # <<<< test

if not os.path.exists(self.path):
Expand All @@ -333,8 +338,6 @@ def RunScript(self):
self.is_success = True
return

# TODO: add a menu item to select the file to run


def AfterRunScript(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions GH/PyGH/test/runner_script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! python3

x = 123
y = 4564
# x = 123
y = 456

a = x - y
c = x + y
Expand Down

0 comments on commit 140c158

Please sign in to comment.