Skip to main content

A killable sleep function for kthread

Project description

A "killable" sleep function for kthread

https://pypi.org/project/kthread/

From kthread's pypi site: Assuming that the thread is not blocked by an operating system call (such as sleep, accept, or recv), the thread will forcefully quit.

pip install kthread-sleep 
import kthread
import sys
from kthread_sleep import sleep
def func():
    try:
        sleep(2000000)
    finally:
        sys.stdout.write("Greetings from Vice City!\n")
        sys.stdout.flush()

t = kthread.KThread(target = func, name = "KillableThread1")
t.start()
sleep(.1)
print(t.is_alive())
t.kill()
sleep(.1)
print(t.is_alive())

True
Greetings from Vice City!
False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kthread_sleep-0.11.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

kthread_sleep-0.11-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page