I just noticed something. I finally hooked up my ASOC app and ran it. The CPU jumped to 100% in about a second. The old ASS APP uses about 1.5% when running the same script basically, on the same machine. It runs rsync in the background at about 20% CPU with nothing else big going on and the app itself is showing 100%…
So I did a test with a new app with one window, a button hooked up to a simple repeat loop:
repeat 100 times
delay 1
end repeat
And bingo… 100% CPU steady on
Any one else notice this? Should this be a concern?
Yes that is ideal. it is a bit tricky though for my current setup. This is just a schematic example and not the actual code:
on processfiles_opt1_opt2_opt3_(filelist,val1,val2,val3,) --many more options than this
repeat with the theFile in filelist
set pid to do shell script "rsync options theFile theDestination > output file" etc...
repeat while pid is in process list
update progress via output file data
delay 1 --here it is so I need to outsource the delay to an NStimer
end
end repeat
--finish up work here is necessary
end processfiles_opt1_opt2_opt3_
the traditional way to do these kind of loops is to hold up the flow while checking to see if the process, in this case rsync in background, is done and then finish the routine. To use an NStimer I will need to break up the repeat loop into handlers to process the files then create the timer which checks the rsync progress and then when rsync finishes, go through the process loop again for the other files or call the finish up handler. not such a bad idea but I have 20+ options to pass to the process loop and I will have to pass them somehow on down the line through these handlers, or create a ton of properties.
I am trying to figure out a way to simulate the delay/update progress loop within the big loop via
Instead of doing "do shell script " you might consider NSTask. During an NSTask you can set an NSNotification to inform you when changes occur. This will not lock up the UI and makes for a more elegant solution.
I tried NSTask years ago in this app but that was ASS and there were problems using it as a call method. So now I am intrigued. I’ll check it out. Let me know if you have any pointers to NSTask info other than the usual Docs. Are you still planning on the MVC video?
One thing that’s possibly not clear from that post is that NSFileHandleReadCompletionNotification is sent every time the task returns some text. So that’s going to be useful to Rob, but he’ll probably also want to add an observer for the task’s NSTaskDidTerminateNotification, so he’ll be notified when it’s finished.
I’m grooving on the possibilities with NSTask. That is my next project.
In the mean time I went ahead and broke up my script using NSTimer to cycle the progress and report back. Guess what?
The cancel button works perfectly. The UI is responsive and even the menulet is completely accessible and responsive during a heavy run. Awesome! The old delay loop in ASS was always a limiting factor for my app. Now it feels more OBJ-c. It has been a haul but ASOC is looking better all the time. I love the way you can just do all the OBJ-c relatively directly.