我有一个 AppleScript 脚本,它运行一个计算插入插件实例的递归函数。在插入每个插件后,该函数会检查 CPU 并确定是否存在 CPU 过载。
如果发现 CPU 过载,它会开始删除插件,直到达到令人满意的程度。然后它返回计算机上加载的实例数。
问题是在一定数量的运行后我得到了堆栈溢出。AppleScript 是否有内部递归线程的限制?
on plugin_recurse(mode, plugin_name, component, track_count, instance_count, has_ref, min_instances, last_max)
try
log "mode - " & mode
if mode is "ret" then return {track_count, instance_count, last_max}
if mode is "add" then
if (instance_count - (10 * track_count) = 0) then
create_track(component)
set track_count to track_count + 1
end if
set instance_count to instance_count + 1
insert_plugin(plugin_name, component, track_count, instance_count)
if has_ref then
set CPUover to false
if min_instances = 1 then
set mode to "ret"
else
set min_instances to min_instances - 1
end if
else
set {CPUover, last_max} to check_cpu(last_max)
end if
if CPUover then
set mode to "sub"
end if
end if
if mode is "sub" then
if instance_count > 1 then
remove_plugin(plugin_name, component, track_count, instance_count)
set instance_count to instance_count - 1
if ((10 * track_count) - instance_count = 10) then
remove_track(track_count)
set track_count to track_count - 1
end if
set {CPUover, last_max} to check_cpu(last_max)
if not CPUover then
set mode to "ret"
end if
else
set mode to "ret"
end if
end if
plugin_recurse(mode, plugin_name, component, track_count, instance_count, has_ref, min_instances, last_max)
on error err
error err
end try
end plugin_recurse