Page 1 of 1

process and sleep function error on a self-calling script

Posted: Tue Oct 15, 2013 4:14 am
by winger

Code: Select all

;#t2.lsp
(set 'ARGS (main-args))
(define (get-arg argname  '_result)
    (let (ix (find argname ARGS))
        (and ix (pop ARGS ix))
        (if (catch (ARGS  ix) '_result) 
            (and (pop ARGS ix) _result)
            nil
        )
    )
)


(constant 'EXECUTE_PATH "/usr/bin/newlisp")

(constant 'ARG_SECOND "t2.lsp")

(constant 'TIME_CLOCK 4000)


(constant 'DEAD (get-arg "--dead"))

(when DEAD
    (write-file (string "t2_txt." (date-value)) (string (date-value)))
    (exit)
)

(while (not DEAD)
    (sleep 2000) ;; Two line code . actually only sleep 2 seconds !!!
    (sleep 2000) ;; Without this will generate an error !!!
    (println "Sleep... " TIME_CLOCK )
    (if CPID (destroy CPID))
    (set 'CPID (process  (join (map string (list EXECUTE_PATH  ARG_SECOND "--clock" TIME_CLOCK  "--dead 4free"  )) " ") ))
    (println "CPID :--> " CPID )
    (println (join (map string (list EXECUTE_PATH  ARG_SECOND "--clock" TIME_CLOCK  "--dead 4free"  )) " "))
    ;(sleep 2000)  ;;Here is also possible to insert the code. 
)
(exit)
t2.lsp is A self-calling script.
anyboday have idea?

And How to suppress output from return values from
load
function?
silent
function no effect.

Re: process and sleep function error on a self-calling scrip

Posted: Tue Oct 15, 2013 3:51 pm
by Lutz
Works well here on a Windows 7 system, with and without the second sleep at the beginning of the while loop and without error message.

The process function is non-blocking. When the child process has started the parent sits in one of the following sleep functions. When the child process finishes, it sends a signal to the parent where it interrupts the current sleep. This explanation is for UNIX like operating systems (seems not to be on Windows).

The silent function only suppresses the display of the return value in the console or terminal window, but it will not suppress the return value itself.

Re: process and sleep function error on a self-calling scrip

Posted: Thu Oct 17, 2013 9:01 am
by winger
I THINK This's a bug ?!

Code: Select all

#p1.lsp
(while 1
    (sleep 5000)
    (dotimes (n 2)
        (process (string "/usr/bin/newlisp " " p2.lsp " n))
    )
)
(exit)

Code: Select all

#ps.lsp
(println "Current PIS is "  (sys-info 7) " ---> " (last $main-args))
(exit)
$ newlisp -v
newLISP v.10.5.4 32-bit on Linux IPv4/6 UTF-8 libffi.
$newlisp p1.lsp

p1 process --- 1 time
p1 process --- 2 time
Current PIS is 891 ---> 0
Current PIS is 892 ---> 1
p1 process --- 3 time
Current PIS is 894 ---> 0
....
oh.................. so rapid
Program did not sleep for 5 seconds, but has continued rapid execution.
sleep function does not execute.

Re: process and sleep function error on a self-calling scrip

Posted: Thu Oct 17, 2013 9:50 am
by Lutz
The sleep in the parent process is interrupted when the child process returns. See my previous post.

Re: process and sleep function error on a self-calling scrip

Posted: Fri Oct 18, 2013 3:57 am
by winger
VERY THX Lutz !
Everything there is reason.
My knowledge is so poor that it did not notice the problem is the signal.
Now I found two ways to avoid this problem.

Code: Select all

(signal 17 "ignore") ; The SIGCHLD signal is sent to the parent of a child process when it exits, is interrupted, or resumes after being interrupted. But can not guarantee that each signal is captured
Or use timer function

Code: Select all

(define (p1)
    (dotimes (n 2) (process (string "/usr/bin/newlisp " " p2.lsp " n)) 
    (timer 'p1 5))
 (p1)

Re: process and sleep function error on a self-calling scrip

Posted: Fri Oct 18, 2013 7:20 am
by Lutz
good solutions!