32 lines
856 B
Python
32 lines
856 B
Python
import asyncio
|
|
import functools
|
|
import datetime, traceback
|
|
#from os import path
|
|
|
|
#conf=j.load(open(path.join(path.dirname(__file__),'config.json')))[path.splitext(path.basename(__file__))[0]]
|
|
|
|
def a():
|
|
yield 1
|
|
gentype=type(a())
|
|
funkies=[]
|
|
|
|
def loop(timer=0,start=None):
|
|
def _loop(funky):
|
|
@functools.wraps(funky)
|
|
async def _wrapper(*args,**kwargs):
|
|
if start is not None:
|
|
ima=datetime.datetime.utcnow()
|
|
await asyncio.sleep((start-ima).total_seconds()) # It'll be very slightly wrong but whatever
|
|
while True:
|
|
try: await funky(*args,**kwargs)
|
|
except Exception: open('error '+str(datetime.datetime.now()),'w').write(traceback.format_exc())
|
|
await asyncio.sleep(timer)
|
|
funkies.append(_wrapper)
|
|
return _wrapper
|
|
return _loop
|
|
|
|
async def _main():
|
|
await asyncio.gather(*map(lambda x:x(),funkies))
|
|
|
|
def run():
|
|
asyncio.run(_main()) |