473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to catch a user interruption?

Dear all,

Some background first:
I have a gtk window where my user pushes some
buttons with a definite pleasure. It usually
amounts to asking the program to try all possible
permutations which can take a long time... and
in between my user wants to change some parameters,
or simply wants to stop. Regularly this programm
outputs some messages corresponding to its state.
So how to do this properly? I can add a button
with "Stop" written on it, but what will it do???
This signal is caught, ok, and then?
Should I use a global variable, a USER_INTERRUPTION
that my Stop-button would put to true and check
regularly for its value?
Any comments on how this is usually and properly done
are most welcomed!! Or sample code, or pointers.
Many thanks,
Amities,
Olivier
Aug 23 '06 #1
8 1969
Olivier wrote:
Dear all,

Some background first:
I have a gtk window where my user pushes some
buttons with a definite pleasure. It usually
amounts to asking the program to try all possible
permutations which can take a long time... and
in between my user wants to change some parameters,
or simply wants to stop. Regularly this programm
outputs some messages corresponding to its state.
So how to do this properly? I can add a button
with "Stop" written on it, but what will it do???
This signal is caught, ok, and then?
Should I use a global variable, a USER_INTERRUPTION
that my Stop-button would put to true and check
regularly for its value?
Any comments on how this is usually and properly done
are most welcomed!! Or sample code, or pointers.
I have been wondering about a similar thing myself. The
only answer I could come up with was pretty much what
you're suggesting ie modifying a global variable and have
the part of the programme which performs the calculations
check regularly about the value of the variable. The tricky
part is to arrange things so that the programme checks often
enough as to not appear to be unresponsive but not so often
that it significantly slows down the calculations.

I haven't actually written any code which does this but pretty
much every chess playing programme will have some such
functionality so you could try and read their code. Crafty for
example is open source and it allows the user to enter input
from the keyboard while it does its calculations. It does its job
pretty well so your answer is hidden in its code. But it's a big
programme so it might be tricky to find it.

Hopefully others will have a more straightforward reply.

Spiros Bousbouras

Aug 23 '06 #2
sp****@gmail.com a écrit :
>[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Aug 23 '06 #3
Olivier wrote:
sp****@gmail.com a écrit :
>[...] it allows the user to enter input
from the keyboard while it does its calculations.

Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.
--
Flash Gordon
Aug 23 '06 #4
Flash Gordon a écrit :
[...]
Since this is really about how it is best to do things in GTK
[...]

Well, I wondered ... The signal handling is gtk stuff ok.
But the way to do that inside is way out of gtk to me.
Seems more like my dear and lost catch/throw mecanism
or exception stuff. I set the background with gtk to be
clear but that could have been anything, even a shell
thing. I agree that it has to do with inputs and outputs
of a program -- but many programs do have both, even
in C, no ?
A.O.
Aug 23 '06 #5
Olivier wrote:
Flash Gordon a écrit :
[...]
>Since this is really about how it is best to do things in GTK
[...]

Well, I wondered ... The signal handling is gtk stuff ok.
But the way to do that inside is way out of gtk to me.
Seems more like my dear and lost catch/throw mecanism
or exception stuff. I set the background with gtk to be
clear but that could have been anything, even a shell
thing. I agree that it has to do with inputs and outputs
of a program -- but many programs do have both, even
in C, no ?
C had no exception handling. The only mechanisms it has for your program
to detect some asynchronous external event are either if the event
causes a signal which you catch with a signal handler, you could then
set a flag (of type volatile sig_atomic_t) which you could regularly
test in you long running calculation, or you regularly polling to see if
the external condition is true. Neither method is very good for handling
this king of thing. There may, on the other hand, be a good way with
GTK, for example using two threads (which C knows nothing about) one for
the user interaction and one for the long running process. The GTK
people will know whether this or some other solution works best with GTK
(I know that on one Delphi application separate threads for user
interface and high speed serial comms worked well) but we won't here.
I'm only suggesting where you are likely to get the best advice for what
is a very common problem for people writing GUI based applications.

By the way, if you are executing code asynchronously (i.e. handling GUI
events) using any other mechanism that standard C signals then the C
language does not tell you how to avoid synchronisation problems, e.g.
your main code being half way through reading a variable when the
asynchronous code writes to it thus causing you to read half of one
value and half of another, even volatile sig_atomic_t is not guaranteed
for that, only for C signals.
--
Flash Gordon.
Aug 23 '06 #6
Flash Gordon a écrit :
[...]
C had no exception handling. The only mechanisms it has for your program
to detect some asynchronous external event are either if the event
causes a signal which you catch with a signal handler, you could then
set a flag (of type volatile sig_atomic_t) which you could regularly
test in you long running calculation, or you regularly polling to see if
the external condition is true. Neither method is very good for handling
this king of thing. There may, on the other hand, be a good way with
GTK, for example using two threads (which C knows nothing about) one for
the user interaction and one for the long running process. The GTK
people will know whether this or some other solution works best with GTK
(I know that on one Delphi application separate threads for user
interface and high speed serial comms worked well) but we won't here.
I'm only suggesting where you are likely to get the best advice for what
is a very common problem for people writing GUI based applications.
That was first class information!! Thanks!!
A.O.
Aug 23 '06 #7
Flash Gordon wrote:
Olivier wrote:
sp****@gmail.com a écrit :
[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.

Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.
This thread and any other is "really" about what the posters
make of it. I understood the GTK reference to be just background
material and considered the central point of the thread to be the
following question:

Assume you have a programme which performs many
calculations. Upon receipt of a signal you want the programme
to receive some input from the user and then resume with
the calculations or perhaps start new calculations based on
the input. How can such a thing be implemented in standard
C ?

Even if the original poster considered a GTK solution to
be the central point of the thread that doesn't mean that
the discussion has to terminate right there for not being
topical. As long as the original , possibly not topical question,
inspires a topical one then the discussion can continue on
the topical question. My previous post in the thread did not
mention GTK at all , it concentrated on standard C so it was
perfectly appropriate for here.

Spiros Bousbouras

Aug 24 '06 #8
sp****@gmail.com wrote:
Flash Gordon wrote:
>Olivier wrote:
>>sp****@gmail.com a écrit :

[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.

This thread and any other is "really" about what the posters
make of it. I understood the GTK reference to be just background
material and considered the central point of the thread to be the
following question:

Assume you have a programme which performs many
calculations. Upon receipt of a signal you want the programme
to receive some input from the user and then resume with
the calculations or perhaps start new calculations based on
the input. How can such a thing be implemented in standard
C ?
It can't. At least, not without you scattering checks throughout the C
code and there are often *far* better solutions. It also can't be done
unless it is a signal in C terms, and I would be somewhat surprised if
clicking a button in the GUI provided a C type signal.
Even if the original poster considered a GTK solution to
be the central point of the thread that doesn't mean that
the discussion has to terminate right there for not being
topical. As long as the original , possibly not topical question,
inspires a topical one then the discussion can continue on
the topical question. My previous post in the thread did not
mention GTK at all , it concentrated on standard C so it was
perfectly appropriate for here.
I can't remember your post, but I believe you when you say it was
topical. I've also not said that the OP should not have asked the
question. What I've said is that the OP is likely to get better advice
on a GTK mailing list. I've also explained why I believe better advice
will be obtained their. Do you have some objection to me suggesting
where better advice is likely to be obtained? All I am trying to do is
get the OP the best possible help in solving the problem and surely
there is nothing wrong with that.
--
Flash Gordon.
Aug 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
8
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
6
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of...
1
by: protista | last post by:
I'm trying to Open a form Without Interruption like msn messenger does for an email alert. I'm doing the same thing, but when my form opens up it interrupts my typing... any help?
2
by: CodeSlayer | last post by:
Hi all, This one really has me and the other .Net developers at my work stumped. I have an application that is doing the following: 1 - attempt to validate that user can create a windows task...
5
by: Bo Peng | last post by:
Dear list, I have not done a thorough test, but it occurs to me that 1. python code can be interrupted by Ctrl-C. 2. A C module, if I add a main() function and run independently, can be...
0
by: Nick | last post by:
Hi eveybody, I need some help regarding the mecanism to put in place to be able to dynamically update a remote object when the assembly where it is defined is modified, and this whitout having...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.