Skip to main content

A package that allows to cancel, certain functions that can be a pain, when working with threading.

Project description

Installation

pip install cancelable

Usage

Without the normal time package:

Sleep

from cancelable import time
import threading

def count():
  i = 1
  while True:
    time.sleep(1)
    print(i)
    i += 1

threading._start_new_thread(count, ())

input("Click enter to cancel counting\n")

time.cancel()

With the normal time package:

from cancelable import time as cancelableTime
import threading

def count():
  i = 1
  while True:
    cancelableTime.sleep(1)
    print(i)
    i += 1

threading._start_new_thread(count, ())

input("Click enter to cancel counting\n")

cancelableTime.cancel()

Input

from cancelable import time, input, cancelInput
import threading

name = ""
def ask():
  global name
  name = input("Your name: ")
  time.cancel()

threading._start_new_thread(ask, ())

time.sleep(5)
cancelInput()

print(name)

To do

Add more functions such as input()

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

cancelable-0.0.4.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

cancelable-0.0.4-py3-none-any.whl (7.0 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