Skip to content

Conversation

Karatuss
Copy link
Contributor

@Karatuss Karatuss commented Aug 16, 2022

Additionally I ran the test below, and it was successful.

# SuperFastPython.com
# example of main thread cannot be interrupting while sleeping
from time import sleep
from threading import Thread
from _thread import interrupt_main
import sys

# task executed in a new thread
def task():
    # block for a moment
    sleep(3)
    # interrupt the main thread
    print('Interrupting main thread now')
    interrupt_main()

# start the new thread
thread = Thread(target=task)
thread.start()
# handle being interrupted
try:
    # block for a long time
    print('Main thread waiting...')
    sleep(7)
except KeyboardInterrupt:
    # terminate main thread
    print('Main interrupted! Exiting.')
    sys.exit()

Close: #3922

@Karatuss Karatuss force-pushed the feature/_thread-interrupt_main branch from 75b6e87 to 57714d0 Compare August 16, 2022 11:43
@Karatuss Karatuss marked this pull request as ready for review August 16, 2022 11:48
@Karatuss Karatuss force-pushed the feature/_thread-interrupt_main branch from 20d3a4f to ac07978 Compare August 16, 2022 13:06
@Karatuss Karatuss force-pushed the feature/_thread-interrupt_main branch from ac07978 to 9dea9b8 Compare August 16, 2022 14:27
@youknowone youknowone added the z-ca-2022 Tag to track contrubution-academy 2022 label Aug 16, 2022
Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

looks good, thank you!

@youknowone youknowone merged commit b1478a6 into RustPython:main Aug 17, 2022
@Karatuss Karatuss deleted the feature/_thread-interrupt_main branch August 17, 2022 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
z-ca-2022 Tag to track contrubution-academy 2022
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_thread.interrupt_main and PyErr_SetInterruptEx
2 participants