-
Content Count
13 -
Joined
-
Last visited
Community Reputation
3 Neutral-
Yes, I'd checked that demo out, and I read the idea of the Python code checking for termination. The challenge I have with my app is the end user will be able to write their own Python code, and maybe won't check for Terminate or a Delphi variable. If they do something silly like make an infinite loop without checking for terminate, then only option will be to crash out with TerminateThread I guess then. Hummm, one idea I just thought of is maybe I can parse their code when it is downloaded to my app, and give warnings if they have any sort of loop without checks.
-
I have an application where a user can write and execute multiple Python scripts, each running in their own thread. I am using ThreadExecMode := emNewInterpreterOwnGIL; The code is now working great, and I can execute multiple Python scripts each in their own parallel thread. Awesome. Now I'd like the user to be able to click a Stop button for a thread, and have the associated Python script stop gracefully via Delphi code. Any way to do this? Does P4D check the thread Terminate property at all? I've tried testing with a simple Python For loop, and it didn't seem to stop it. Checked this forum, and didn't see anything. ChatGPT just gives nonsense (nothing new there!). I could call the Windows APi TerminateThread function in a worst case, but that can cause all sorts of havoc. Any ideas on how to more gracefully stop a P4D thread?
-
Can't print from Python script thread to Delphi main thread
Martybartfast replied to Martybartfast's topic in Python4Delphi
BTW for anyone else doing ThreadExecMode := emNewInterpreterOwnGIL; and using a module, do make sure in your module you set this property: MultInterpretersSupport := mmiPerInterpreterGIL; That cause me a bit of head scratching for a while! -
Can't print from Python script thread to Delphi main thread
Martybartfast replied to Martybartfast's topic in Python4Delphi
@pyscripterAwesome stuff!!! Works perfectly now. Thank you so much, and thanks for making such a great set of components -
Martybartfast changed their profile photo
-
Can't print from Python script thread to Delphi main thread
Martybartfast replied to Martybartfast's topic in Python4Delphi
Ahhh, yes. If I set ThreadExecMode := emNewState; then I see print output. Hummmm... need to think what to do then. -
Can't print from Python script thread to Delphi main thread
Martybartfast posted a topic in Python4Delphi
I emailed @pyscripter about an issue I was having with getting a dynamically created TPythonThread to print to a dynamically created TPythonInputOutput. He suggested I should post here. I've tried some of the suggested ideas, but alas still no luck with print() from a threaded script appearing on the main thread memo. I have now created a minimal project with my code, see attached. Can anyone explain what I'm doing wrong?! The script seems to run (the for loop reacts as expected), but I just can't see the Print output. Much appreciate any help, thank you! P4D Showtime test.zip -
Here's the full unit XTEC_HttpSrv_GUI.pas.zip
-
I don't think anything is wrong with the Javascript. Here's why: I'm using the code from the ICS Web Sockets sample: function init(){ var host = "ws://192.168.1.9:42071/xcs"; try { socket = new WebSocket(host); log('WebSocket - status ' + socket.readyState); socket.onopen = function(msg){ log("Welcome - status " + this.readyState); }; socket.onmessage = function(msg){ log("Received (" + msg.data.length + " bytes): " + (msg.data.length < 5000 ? msg.data : (msg.data.substr(0, 30) + '...'))); }; socket.onclose = function(msg){ log("Disconnected - status " + this.readyState); }; } catch(ex) { log(ex); } } So, for testing I made a global IWebSocketConnection variable, then in the Connected callback I copy the 'conn' IWebSocketConnection to my array. Then I can use that to successfully send to the browsers. So it seems the Javascript is fine. I just can't work out how to access the IWebSocketConnection for each client. I do NOT want to have my own array of connections... this must be possible another way? This is my send code with my work-around (s = "Hello from Martin"): var WebSocketConn : array of IWebSocketConnection; ... procedure THttpGUI.WebSocketServer_Connected(Sender: TObject; con: IWebSocketConnection); var i: Integer; msg: String; begin if Assigned(con) then begin ... setLength(WebSocketConn, WebSocketServer.ClientCount); WebSocketConn[WebSocketServer.ClientCount - 1] := con; // Store connection - testing!!! ... end; end; // Send a string to all connected clients (browsers). procedure THttpGUI.WebSocket_SendString(s : string); var n : integer; begin if assigned(WebSocketServer) then begin for n := 0 to WebSocketServer.ClientCount-1 do begin WebSocketConn[n].sendString(s); // This works, but is NOT the right way to do this!!! end; end; end; As you see, I get my "Hello from Martin" string fine on the browser. Hummmm.... much appreciate any help!
-
I'm using ICS Web Sockets, and everything is working good so far - browsers connect to my server, and the ICS "echo" sample works fine. However, I need to send an unsolicited string from the server to all connected clients. Anyone know how to do this? I've tried and tried, and can't find any way to access the web socket clients. If I just do "Webserver.client[n].sendstr(s);" then the browser just disconnects. What I'm trying to do this something like this: WebSocketServer: TWSocketServer; ... procedure THttpGUI.Start; begin ... if not(assigned(WebSocketServer)) then // Don't do if already created begin WebSocketServer := TWSocketServer.Create(nil); // Create the WebSocket server WebSocketServer.Proto := 'tcp'; // TCP/IP protocol WebSocketServer.ClientClass := TWebSockSrvClient; // Web socket WebSocketServer.Banner := ''; // Remove banner because we handle websocket handshake WebSocketServer.OnBgException := WebSocketServer_BgException; WebSocketServer.OnClientConnect := WebSocketServer_ClientConnect; WebSocketServer.OnClientDisconnect := WebSocketServer_ClientDisconnect; end; end; // Connection stuff all works fine, not shown here ... // Send a string to all connected clients (browsers). procedure THttpGUI.WebSocket_SendString(s : string); var n : integer; begin if assigned(WebSocketServer) then begin for n := 0 to WebSocketServer.ClientCount-1 do begin WebSocketClient[n].sendString(s); // Something like this!!! end; end; end;
-
Ah yes, I forgot. Thanks anyway. Anyone else can help?
-
Hi again Angus. So I've got Web Sockets working in my application, everything connects as it should, and I can send a welcome message in the Connected event. Problem now is that once the connection is established, if I then send a string to the client(s), the browser immediately disconnects from the Web Socket connection. Delphi: s : string; n : integer; b : integer; ... s := 'Hello'; for n := 0 to WebSocketServer.ClientCount-1 do begin b := WebSocketServer.Client[n].SendStr(s); end; b does indeed show the correct number of characters have been sent. The HTML is taken directly from your sample: function init(){ var host = "ws://127.0.0.1:42071/xcs"; try { socket = new WebSocket(host); log('WebSocket - status '+socket.readyState); socket.onopen = function(msg){ log("Welcome - status "+this.readyState); }; socket.onmessage = function(msg){ log("Received ("+msg.data.length+" bytes): " + (msg.data.length < 5000 ? msg.data : (msg.data.substr(0, 30) + '…'))); }; socket.onclose = function(msg){ log("Disconnected - status "+this.readyState); }; } catch(ex) { log(ex); } } Any idea what I'm doing wrong?
-
Excellent, that works. Thank you!
-
Hi Angus. I'm trying to run the ICS "OverbyteIcsWebSocketSrv.dproj" sample in Delphi 11.1, but I get errors when I build: [dcc32 Error] OverbyteIcsWebSockets.pas(695): E2003 Undeclared identifier: 'Base64Encode'. [dcc32 Error] OverbyteIcsWebSockets.pas(811): E2003 Undeclared identifier: 'Base64Encode' Delphi can't find the "Base64Encode" function. Any ideas? Am I being totally stupid? :) I've looked all over for a solution... Hope you can assist. Thanks mate!