gawel / aiocron

Crontabs for asyncio
MIT License
338 stars 20 forks source link

stop before first run wont work #6

Closed inshua closed 6 years ago

inshua commented 6 years ago
cron = aiocron.crontab('* * * * * */2', func=test, start=True, loop = loop)
cron.stop()  # immediately stop

the test will still run

after test run once time, stop can make effect.

gawel commented 6 years ago

I guess you have to stop the loop too ?

gawel commented 6 years ago

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

gawel commented 6 years ago

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())
gawel commented 6 years ago

Think I got it. Feel free to reopen the issue if needed

inshua commented 6 years ago

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()
gawel commented 6 years ago

Did you try with the latest version ? Your code works for me. The date is never printed

inshua commented 6 years ago

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'
>>> 
gawel commented 6 years ago

Which python version ? I'm using 3.5.2 and it works.

gawel commented 6 years ago

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
inshua commented 6 years ago

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.

gawel commented 6 years ago

I had the same problem... It's probably better to use pip install -e /whereisthecheckout