Skip to main content

some useful async schedule class, which use coroutine to make more efficient, refer to the standard library `sched`

Project description

  • sled


an async scheduler module, it was written in the 2021 christmas to pass the boring christmas .

The sled module defines some class which implements a general purpose event scheduler. some useful async schedule class that refer to the standard library sched.

AsyncPriorityScheduler use the same namedtuple and the same interface to the sched. if u do not need the priority attribute. AsyncScheduler, PerfSchduler is perfer to use.

all of that needed to be used in async module which required to make sure event loop is running.

PerfSchduler, don't store the event. AsyncScheduler, don't have the priority. AsyncPriorityScheduler is almost the same to the sched, but just Coroutine, not the thread.


参考标准库sched实现的一个基于协程的事件调度框架。
可以用于执行一些定时任务。
其中 AsyncPriorityScheduler 可以兼容 标准库sched模块。
PerfScheduler, AsyncScheduler 拥有比标准库更易用的定时任务函数. timer 和 ticker。
但是两者都有一定的限制,不支持自定义的时间函数。
性能首选 PerfScheduler
不需要优先级,但是需要查看积累的任务,选用 AsyncScheduler
需要在异步编程环境下,替换 sched 选用 AsyncPriorityScheduler


intall

pip install sled


usage
import time
import asyncio
from sled import AsyncPriorityScheduler, AsyncScheduler, PerfScheduler

def func(s):
    print(s, time.time())
    
async def afunc(s):
    print(s, time.time())

# using AsyncPriorityScheduler
schedule = AsyncPriorityScheduler()
schedule.enter(3, 1, func, argument=('test enter',)) # run a task in laster 3 seconds, priority 1.
schedule.enterabs(time.time()+3, 1, afunc('test enterabs async',))

# using AsyncScheduler
asyncSchedule = AsyncScheduler()
asyncSchedule.timer(3, afunc('test async timer'))
asyncSchedule.ticker(1, 3, afunc, argument=('test AsyncScheduler',)) # interval is 1, times is 3

# using PerfScheduler
perfSchedule = PerfScheduler()
perfSchedule.ticker(2, 3, afunc, argument=('test PerfScheduler',))

# make sure loop is running in ur code
loop = asyncio.get_event_loop()
loop.run_forever()

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

sled-0.0.4.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

sled-0.0.4-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file sled-0.0.4.tar.gz.

File metadata

  • Download URL: sled-0.0.4.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for sled-0.0.4.tar.gz
Algorithm Hash digest
SHA256 bc5c0c8cc1beeb821577dfb0b870b39ce386b0ff7a757afc6c6d76f3cbd55fdc
MD5 8f3dde2790b03cbdf781443fa6e7f508
BLAKE2b-256 5caa90001b60cf13d6396deccbf73d9835c78c16524690094dd7e76e69a9c783

See more details on using hashes here.

File details

Details for the file sled-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: sled-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for sled-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e983e45ce34057259e516fdf904949e5c7e08c5beac9de83e305959f0f9baee1
MD5 31c9389f631a2bdc6cdbf6dcdd5bdec1
BLAKE2b-256 d622270537c9e2c9a5f09a5e6a380b6222d0a6bcc19b60a6388b2d4c55ee0d30

See more details on using hashes here.

Supported by

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