help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Catching Figure close button - callbacks not running?


From: Pantxo Diribarne
Subject: Re: Catching Figure close button - callbacks not running?
Date: Wed, 30 Jan 2019 12:46:59 +0100


Le mer. 30 janv. 2019 à 12:01, Pavel Hofman <address@hidden> a écrit :
Hi,

Dne 30. 01. 19 v 9:13 Pantxo napsal(a):
>
> When graphics callback events are fired from the GUI (main thread), they
> cannot be executed right away because the interpreter (worker thread) may be
> busy with some other task, so the events are stored in an event queue.

IIUC that does mean the callbacks are executed in the main worker thread
and do not have a separate thread. That is how my code behaves.
Callback functions are written in m-code, as such they must be interpreted and are thus executed in the "interpreter" (or "worker") thread. The "main" (or "GUI")  thread is the one in which GUI objects (as figures) live.


> here are the possible ways to execute the events:
> * The interpreter is idle: every 100ms, Octave processes the eventual events
> that have been stored in the queue

Does calling pause() make the interpreter idle, processing the events?
While waiting in
https://octave.sourceforge.io/zeromq/function/zmq_poll.html does not
make the interpreter idle? That would explain the different behavior of
Tony's and my code (pause() - callbacks are processed vs. zmq_poll() -
callbacks are not processed).
None of those make the interpreter idle: until "pause" or "zmq_poll" have returned, the interpreter is busy. The difference is that the "pause" explicitly calls process_events (only once in Octave 4.4, every 100ms in the soon released Octave 5) while I guess "zmq_poll" doesn't.
If you want to obtain the same kind of behavior you could do something like

havedata = false;
while (! havedata)
  havedata = zmq_poll (sock, 100);
  drawnow ();
endwhile


>
> So instead of "flush the event queue" one should read "process events in the
> queue", or anything that does not mean "discard" :-).
>

Yes that would be a good explanation. The fact that the callback is
executed by the main work thread is important IMO.

Please what would be the best practice (if any) for executing callbacks
in another thread so that the main worker thread does not have to wait
for the callback to finish?
I don't understand your use case, but anyway, as stated above, callback functions will always end up being executed in the "interpreter" (not "main") thread, where your program is executed.
 

Pantxo

reply via email to

[Prev in Thread] Current Thread [Next in Thread]