Useful python utilities with less effort.
Project description
useless-py
Useful python utilities with less effort.
Usage
set_interval() function
from useless import set_interval
def my_function():
print "Hello world!"
set_interval(my_function, 500) # Caution! Non-blocking.
time.sleep(10) # Create blocking code
@interval decorator
from useless import interval
@interval(500)
def my_function():
print "Hello world!"
my_function() # Caution! Non-blocking.
time.sleep(10) # Create blocking code
set_timeout() function
from useless import set_timeout
def my_function():
print "Hello world!"
set_timeout(my_function, 500)
@timeout decorator
from useless import timeout
@timeout(1000)
def my_function():
print "Hello world!"
my_function()
set_time_limit() function
from useless import set_time_limit, TimeLimitExceededError
import time
def my_function():
time.sleep(1)
print "Hello world!"
# if time limit is enough
set_time_limit(my_function, 1500)
# if time limit is not enough, raises TimeLimitExceededError
try:
set_time_limit(my_function, 500)
except TimeLimitExceededError as e:
print e.message
@time_limit decorator
from useless import time_limit, TimeLimitExceededError
import time
@time_limit(1500)
def my_function1():
time.sleep(1)
print "Hello world!"
@time_limit(500)
def my_function2():
time.sleep(1)
print "Hello world!"
# if time limit is enough
my_function1()
# if time limit is not enough, raises TimeLimitExceededError
try:
my_function2()
except TimeLimitExceededError as e:
print e.message
To-Do
Too many to list here :)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
useless-py-1.0.1.zip
(4.0 kB
view hashes)