Forum > Networking and Web Programming
Solved: Calling application.run for thttpapplicat doesn't return for finally par
vangli:
Yes Чебурашка. It look like I has to create a separate thread like you describe. The while statement has no effect. Application.Terminate doesn't work because Application.Run is blocking, I think, in my oversimplified approach. ::)
vangli:
Found a workable way. Basically moved the exit information to the HandleSigInt procedure, and there calling Application.Terminate, which set Application.Terminated to True. Wait for the flag to be set, and then free the hole application Instance. And then write some exit information before Halt, and I am back to command line. Wonder if this method introduce some kind of Memory leakage.
Thks Чебурашка for your kind help.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program aWebServer; {$mode objfpc}{$H+} uses {$ifdef UNIX} cthreads, cmem, {$endif} fphttpapp, httpdefs, httproute, sysutils, BaseUnix; procedure HandleSigInt(aSignal: LongInt); cdecl;begin Writeln(LineEnding,'Calling terminate after SIGINT'); Application.Terminate; while not Application.Terminated do Sleep(10); Application.FreeInstance; writeln('Write some information when application ends....'); Halt(0);end; begin if FpSignal(SigInt, @HandleSigInt) = signalhandler(SIG_ERR) then begin Writeln('Failed to install signal error: ', fpGetErrno); Halt(1); end; Writeln('Starting application, press CTRL+C to terminate...'); try Application.Port := 8081; Application.Threaded := true; Application.Initialize; Application.Run; finally writeln('Error!'); end;end.
zen010101:
It is a bug mentioned here:
https://gitlab.com/freepascal.org/fpc/source/-/issues/36741#original-reporter-info-from-mantis-luca-olivlucareporter-name-luca-olivetti
There is an ugly workaround:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure signalHandler(signum: cint); cdecl;begin Raise Exception.Create('EXIT THE APPLICATION');end;
Everything is working fine, but you might see an exception message pop up, no need to worry about any memory leaks.
Navigation
[0] Message Index
[*] Previous page