Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @interruptable macro #554

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

sebastiendesignolle
Copy link
Collaborator

Works like a charm! Scoping was indeed a bit delicate...

In many cases, we could actually skip the extra iteration since everything is recomputed one last time, but there's a argument for that if needed (default to 1 currently).

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

very cool - and even better than we discussed with the number of final iterations adjustable. i think 1 is good for some algorithms. stupid question: upon ctrl-c is the "remainder" of the loop iteration still correctly executed? I assume yes? @sebastiendesignolle

@sebastiendesignolle
Copy link
Collaborator Author

Unfortunately no! The macro only has access to the body of the loop as a whole, so the breaking point is unknown. This may indeed lead to unexpected behaviours, but this is probably fine for testing, which is anyway the purpose of this feature.

Btw, I've just done a quick performance test and could not see any measurable drawback.

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

Unfortunately no! The macro only has access to the body of the loop as a whole, so the breaking point is unknown. This may indeed lead to unexpected behaviours, but this is probably fine for testing, which is anyway the purpose of this feature.

Btw, I've just done a quick performance test and could not see any measurable drawback.

let's discuss this soon - maybe there is a way to ensure that always "full" loops are executed.

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

from the logic it seems that the full loop is completed as you only change the variable interrupted via the exception

@sebastiendesignolle
Copy link
Collaborator Author

As discussed today, this feature is unfortunately not possible in Julia. Unlike languages with longjmp-style exception handling (like C's setjmp/longjmp or SEH in Windows), Julia's exceptions immediately unwind the stack to the nearest catch. This means that we have no way of going back to the code where the Ctrl-C raised the exception.

I've just added a warning, this is ready to merge for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add Ctrl-C handling to prematurely end solve (convenience feature)
2 participants