Skip to content

Add runner context interrupting#256

Open
TOMMy-Net wants to merge 1 commit intogo-python:mainfrom
TOMMy-Net:main
Open

Add runner context interrupting#256
TOMMy-Net wants to merge 1 commit intogo-python:mainfrom
TOMMy-Net:main

Conversation

@TOMMy-Net
Copy link

Adding context interrupting based on atomics, for breaking code runner.

Copy link
Collaborator

@ncw ncw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a nice change - thank you

See inline for comments

closed bool
running sync.WaitGroup
done chan struct{}
interrupt int32 // atomic; non-zero means KeyboardInterrupt pending
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using atomic.Int32 here saves mistakes

Copy link
Author

@TOMMy-Net TOMMy-Net Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go 1.8, not support this type of atomics @ncw

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I forgot we are still on 1.8. Maybe we should upgrade the minimum requirements. What do you think?

defer ctx.Close()

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work on windows I think.

We probably only need os.Interrupt anyway, INT and TERM are not generated by the keyboard.

Perhaps see what python3 does with those signals?

Copy link
Author

@TOMMy-Net TOMMy-Net Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"INT and TERM are not generated by the keyboard." You sure? I thought that INT was called by pressing CTRL+C.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right of course. However os.Interrrupt is the same as sigint on Unix machines, so it should cover everything we need

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.

2 participants