Pre-stream commit.
This commit is contained in:
parent
4cad6a574f
commit
53e4be0439
@ -144,15 +144,13 @@ func stop():
|
||||
func is_running():
|
||||
return not (_worker_thread == null)
|
||||
|
||||
func _normal_communication_loop(sock : StreamPeer, address):
|
||||
|
||||
while not _should_quit:
|
||||
func _normal_communication_loop_iteration(sock : StreamPeer, address):
|
||||
|
||||
if sock.poll() != OK:
|
||||
break
|
||||
return FAILED
|
||||
|
||||
if sock.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||
break
|
||||
return FAILED
|
||||
|
||||
# Get new data.
|
||||
_state_lock.lock()
|
||||
@ -161,7 +159,7 @@ func _normal_communication_loop(sock : StreamPeer, address):
|
||||
var incoming_bytes = sock.get_data(available_bytes)
|
||||
_packet_buffer.add_bytes(PackedByteArray(incoming_bytes[1]))
|
||||
if incoming_bytes[0] != OK:
|
||||
break
|
||||
return FAILED
|
||||
_state_lock.unlock()
|
||||
|
||||
# Send all packets from queue.
|
||||
@ -176,7 +174,7 @@ func _normal_communication_loop(sock : StreamPeer, address):
|
||||
sock.put_data(next_outgoing_packet)
|
||||
_state_lock.unlock()
|
||||
|
||||
OS.delay_usec(1)
|
||||
return OK
|
||||
|
||||
func _client_thread_func(address):
|
||||
|
||||
@ -189,7 +187,11 @@ func _client_thread_func(address):
|
||||
if connect_err == OK:
|
||||
_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.
|
||||
_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):
|
||||
|
||||
_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
|
||||
# between Python and GDScript.
|
||||
|
@ -4,7 +4,6 @@ import importlib.util
|
||||
import sys
|
||||
import argparse
|
||||
import time
|
||||
# import psutil
|
||||
import json
|
||||
|
||||
import KiriPacketSocket
|
||||
@ -22,7 +21,6 @@ if True:
|
||||
|
||||
arg_parser.add_argument("--script", type=str, 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()
|
||||
|
||||
@ -103,11 +101,6 @@ if True:
|
||||
packet_socket.stop()
|
||||
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()
|
||||
while next_packet:
|
||||
this_packet = next_packet
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import time
|
||||
|
||||
try:
|
||||
import KiriPythonRPCWrapper
|
||||
except Exception as e:
|
||||
print(e)
|
||||
time.sleep(5)
|
||||
|
@ -125,8 +125,7 @@ func start_process():
|
||||
python_exe_path,
|
||||
wrapper_script_path,
|
||||
"--script", python_script_path,
|
||||
"--port", open_port,
|
||||
"--parent_pid", OS.get_process_id()]
|
||||
"--port", open_port]
|
||||
|
||||
print("startup command: ", startup_command)
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
The big ones:
|
||||
- Handle bundling of the actual Python modules we want to use.
|
||||
- First-time setup of requirements (pip, etc).
|
||||
Done:
|
||||
x Handle bundling of the actual Python modules we want to use.
|
||||
x Remove dependency on psutil.
|
||||
- Clean up removal of psutil.
|
||||
- Remove xterm dependency, or make it like a debug-only thing.
|
||||
- Test on WINE/Windows.
|
||||
- Documentation.
|
||||
- how to use .kiri_export_python
|
||||
x Clean up removal of psutil.
|
||||
x remove parent_pid from wrapper script
|
||||
x remove KiriPythonRPCWrapper_start.py
|
||||
x remove test_rpc.py
|
||||
|
||||
The big ones:
|
||||
|
||||
- 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.
|
||||
at: ~Thread (core/os/thread.cpp:102)
|
||||
|
||||
- remove KiriPythonRPCWrapper_start.py
|
||||
- remove test_rpc.py
|
||||
- First-time setup of requirements (pip, etc).
|
||||
- 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
|
||||
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user