Re: More embedding questions

Hammond, Mark (MHammond@jm.cmutual.com.au)
Tue, 21 Feb 95 09:33:00 PST

> | You could use the mechanisms intended for the debugger, which give you
> | control at each executed line, but this slows things down quite a bit.
> | You can also use this to get control only once per function call, but
> | that means a simple infinite loop can't be caught. If you hide the
> | signal module from your users, you could use it yourself to set an
> | alarm timer which executes every second or so. If you have threads,
> | you could have another thread keep an eye open as per
> | sys.check_interval.
>
> Hmmm... okay, well it sounds like -something- can be done. :) When I get
> to that point, I'll just have to decide on what the best option is. It
> would be nice to allow the scripts to sit in a loop while the program
still
> managing the GUI, but without threading that probably is not a reasonable

This gets very hard in a gui. In my experience, _most_ of the Python code
executing in a GUI is in response to GUI messages, and this often excludes
threads.

Typically, there will be a single thread managing the GUI, and other worker
threads that do not use the GUI.

Without threads, some gui OS' have the ability to dispatch pending messages
during work - eg, when processing a "Click" message, you can dispatch other
messages waiting. However, this often makes state management very difficult
(eg, imagine processing a "button up" message before completing the "button
down" processing)

> thing to do. At any rate, the only thing that this is really needed is
for
> an emergency abort by the user.
To achieve this, I have another thread, which actually creates a button
saying "Break". The user can click on this button at any time. All this
button does is to set the Python internal "interrupted" variable. Note,
however, that this can/will not break a system call - eg, if your Python
program is in a "read" statement on a socket, and is blocked waiting for
socket data, then setting the Python interrupted flag will have no effect.
I havent looked into using signals as well to abort any sleeping OS calls.

Some of the issues you have been discussing are very interesting, and I have
interest in most of these topics myself. I would be interested to hear what
you come up with on these issues (especially the "multiple sys modules"
simulation!)

Mark.
Mark.