Disp in background thread
14 次查看(过去 30 天)
显示 更早的评论
Is it possible to disp some text to main console while executing code in background? I have an infinite function that is started by parfeval but it's difficult to track what's going on there and simply putting disp in code shows nothing (I guess that's beceause parallel worker has its own console output).
0 个评论
采纳的回答
Edric Ellis
2018-3-16
q = parallel.pool.DataQueue();
afterEach(q, @disp);
f = parfeval(@myFcn, 0, q);
function myFcn(q)
for idx = 1:100
pause(3);
send(q, sprintf('Iteration: %d at time: %s', idx, string(datetime)));
end
end
更多回答(1 个)
Michael Schlagmüller
2022-11-23
We have a related issue here.
We have a .NET assembly which has a callback
function DeviceLogger(level, message)
disp(message)
end
which is registered via
NET.addAssembly('DeviceAssembly');
DeviceAssembly.setLogger(@DeviceLogger);
The issue is that our customers using our assembly can collide with writing on the console, e.g., via
while(true)
pause(0.1)
disp('The customer outputs something to the console.')
DeviceAssembly.myfunc()
end
This freezes Matlab most often when the DeviceLogger is called. When the user does not do any disp messages or the user disp messages do not collide with the logger disp messages - everything works fine.
It seems from my testing that when there are two disp functional calls at the same time (one from the C# and one from the Matlab main thread) Matlab freezes.
The question is how to get around the problem of writing something to the console from the assembly (this is where we have control over) while the user, our customer (we have no control over), could also write something on the console.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!