Pre-stream commit.

This commit is contained in:
Kiri 2024-07-14 14:49:44 -07:00
parent 4cad6a574f
commit 53e4be0439
6 changed files with 56 additions and 88 deletions

View File

@ -144,15 +144,13 @@ func stop():
func is_running(): func is_running():
return not (_worker_thread == null) return not (_worker_thread == null)
func _normal_communication_loop(sock : StreamPeer, address): func _normal_communication_loop_iteration(sock : StreamPeer, address):
while not _should_quit:
if sock.poll() != OK: if sock.poll() != OK:
break return FAILED
if sock.get_status() != StreamPeerTCP.STATUS_CONNECTED: if sock.get_status() != StreamPeerTCP.STATUS_CONNECTED:
break return FAILED
# Get new data. # Get new data.
_state_lock.lock() _state_lock.lock()
@ -161,7 +159,7 @@ func _normal_communication_loop(sock : StreamPeer, address):
var incoming_bytes = sock.get_data(available_bytes) var incoming_bytes = sock.get_data(available_bytes)
_packet_buffer.add_bytes(PackedByteArray(incoming_bytes[1])) _packet_buffer.add_bytes(PackedByteArray(incoming_bytes[1]))
if incoming_bytes[0] != OK: if incoming_bytes[0] != OK:
break return FAILED
_state_lock.unlock() _state_lock.unlock()
# Send all packets from queue. # Send all packets from queue.
@ -176,7 +174,7 @@ func _normal_communication_loop(sock : StreamPeer, address):
sock.put_data(next_outgoing_packet) sock.put_data(next_outgoing_packet)
_state_lock.unlock() _state_lock.unlock()
OS.delay_usec(1) return OK
func _client_thread_func(address): func _client_thread_func(address):
@ -189,7 +187,11 @@ func _client_thread_func(address):
if connect_err == OK: if connect_err == OK:
_set_state(KiriSocketState.CONNECTED) _set_state(KiriSocketState.CONNECTED)
_normal_communication_loop(sock, address) while not _should_quit:
var err = _normal_communication_loop_iteration(sock, address)
if err != OK:
break
OS.delay_usec(1)
# We are now disconnected. # We are now disconnected.
_set_state(KiriSocketState.DISCONNECTED) _set_state(KiriSocketState.DISCONNECTED)
@ -214,7 +216,12 @@ func _set_state(state : KiriSocketState, error_string=null):
func _server_to_client_thread_func(connection : StreamPeerTCP, address): func _server_to_client_thread_func(connection : StreamPeerTCP, address):
_set_state(KiriSocketState.CONNECTED) _set_state(KiriSocketState.CONNECTED)
_normal_communication_loop(connection, address)
while not _should_quit:
var err = _normal_communication_loop_iteration(connection, address)
if err != OK:
break
OS.delay_usec(1)
# FIXME: Missing some error handling here due to exception differences # FIXME: Missing some error handling here due to exception differences
# between Python and GDScript. # between Python and GDScript.

View File

@ -4,7 +4,6 @@ import importlib.util
import sys import sys
import argparse import argparse
import time import time
# import psutil
import json import json
import KiriPacketSocket import KiriPacketSocket
@ -22,7 +21,6 @@ if True:
arg_parser.add_argument("--script", type=str, required=True) arg_parser.add_argument("--script", type=str, required=True)
arg_parser.add_argument("--port", type=int, required=True) arg_parser.add_argument("--port", type=int, required=True)
arg_parser.add_argument("--parent_pid", type=int, required=True)
args = arg_parser.parse_args() args = arg_parser.parse_args()
@ -103,11 +101,6 @@ if True:
packet_socket.stop() packet_socket.stop()
raise Exception("Disconnected from RPC host.") raise Exception("Disconnected from RPC host.")
# # Watch parent PID so we can clean up when needed.
# if not psutil.pid_exists(args.parent_pid):
# packet_socket.stop()
# raise Exception("RPC host process died")
next_packet = packet_socket.get_next_packet() next_packet = packet_socket.get_next_packet()
while next_packet: while next_packet:
this_packet = next_packet this_packet = next_packet

View File

@ -1,10 +0,0 @@
#!/usr/bin/python3
import time
try:
import KiriPythonRPCWrapper
except Exception as e:
print(e)
time.sleep(5)

View File

@ -125,8 +125,7 @@ func start_process():
python_exe_path, python_exe_path,
wrapper_script_path, wrapper_script_path,
"--script", python_script_path, "--script", python_script_path,
"--port", open_port, "--port", open_port]
"--parent_pid", OS.get_process_id()]
print("startup command: ", startup_command) print("startup command: ", startup_command)

View File

@ -1,12 +1,12 @@
The big ones: Done:
- Handle bundling of the actual Python modules we want to use. x Handle bundling of the actual Python modules we want to use.
- First-time setup of requirements (pip, etc).
x Remove dependency on psutil. x Remove dependency on psutil.
- Clean up removal of psutil. x Clean up removal of psutil.
- Remove xterm dependency, or make it like a debug-only thing. x remove parent_pid from wrapper script
- Test on WINE/Windows. x remove KiriPythonRPCWrapper_start.py
- Documentation. x remove test_rpc.py
- how to use .kiri_export_python
The big ones:
- Un-thread the GDScript side of PacketSocket. - Un-thread the GDScript side of PacketSocket.
@ -17,5 +17,12 @@ WARNING: A Thread object is being destroyed without its completion having been r
Please call wait_to_finish() on it to ensure correct cleanup. Please call wait_to_finish() on it to ensure correct cleanup.
at: ~Thread (core/os/thread.cpp:102) at: ~Thread (core/os/thread.cpp:102)
- remove KiriPythonRPCWrapper_start.py - First-time setup of requirements (pip, etc).
- remove test_rpc.py - Remove xterm dependency, or make it like a debug-only thing.
- Test on WINE/Windows.
- Documentation.
- how to use .kiri_export_python
- example Python module from OUTSIDE the addon

View File

@ -1,28 +0,0 @@
#!/usr/bin/python3
import time
import KiriPacketSocket
ps = KiriPacketSocket.PacketSocket()
ps.start_server(("127.0.0.1", 9506))
connections = []
while True:
psc = ps.get_next_server_connection()
if psc:
print("Got connection.")
connections.append(psc)
psc.send_packet(b'ABCDEFGHIJ')
for conn in connections:
p = conn.get_next_packet()
while p:
print(p)
conn.send_packet(p + b'1')
p = conn.get_next_packet()
time.sleep(0.0001)