Skip to content

A python module that can cancel time.sleep while it's sleeping

License

Notifications You must be signed in to change notification settings

jona799t/Cancelable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

A python module that can cancel time.sleep while it's sleeping

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages