Closed inshua closed 6 years ago
I guess you have to stop the loop too ?
This works fine:
import aiocron
import asyncio
loop = asyncio.get_event_loop()
async def test():
await asyncio.sleep(5)
print('toto')
async def main():
cron = aiocron.crontab('* * * * * */2', func=test, start=True, loop=loop)
cron.stop() # immediately stop
loop.run_until_complete(main())
'toto' is never printed
Hm, never mind. You're write. This print 'toto':
# -*- coding: utf-8 -*-
import aiocron
import asyncio
loop = asyncio.get_event_loop()
async def test():
await asyncio.sleep(5)
print('toto')
async def main():
cron = aiocron.crontab('* * * * * */2', func=test, start=True, loop=loop)
cron.stop() # immediately stop
await asyncio.sleep(6)
loop.run_until_complete(main())
Think I got it. Feel free to reopen the issue if needed
see below:
from datetime import datetime
import aiocron
import asyncio
import sys
async def wait() :
await asyncio.sleep(500)
loop = asyncio.get_event_loop()
async def test() :
print(datetime.now())
# cron.stop() # would work
cron = aiocron.crontab('* * * * * */2', func=test, start=True, loop = loop)
cron.stop() #not work
loop.run_until_complete(wait())
loop.close()
Did you try with the latest version ? Your code works for me. The date is never printed
I installed from pip, now I run git clone
, setup.py install
, but this problem still exists.
aiocron version:
>>> import aiocron
>>> import pkg_resources
>>> pkg_resources.get_distribution("aiocron").version
'0.8.dev0'
>>>
Which python version ? I'm using 3.5.2 and it works.
And the output of my pip freeze:
% ./bin/pip freeze 1 ↵
aiocron==0.7
croniter==0.3.19
python-dateutil==2.6.1
six==1.10.0
After pip install aiocron -U
it works for me. Thanks.
my prev version is 0.6.
but since I have run setup.py
, my environment should be newest. I will make it clear.
I had the same problem... It's probably better to use pip install -e /whereisthecheckout
the
test
will still runafter
test
run once time,stop
can make effect.