Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 26 15:19
    agronholm commented #588
  • Jan 26 15:18
    falk-stefan commented #588
  • Jan 26 15:18
    falk-stefan commented #588
  • Jan 26 15:14
    agronholm commented #588
  • Jan 26 15:11
    falk-stefan opened #588
  • Jan 26 15:11
    falk-stefan labeled #588
  • Jan 26 06:33
    Abyssknight commented #559
  • Jan 25 12:20
    agronholm commented #291
  • Jan 25 12:17
    yhling commented #488
  • Jan 20 02:32
    riyadparvez commented #285
  • Jan 19 07:55
    w-Bro commented #508
  • Jan 18 16:36
    saasglue closed #587
  • Jan 18 16:35
    saasglue opened #587
  • Jan 05 14:32
    agronholm commented #465
  • Jan 05 13:46
    dariosm commented #465
  • Jan 03 19:48

    agronholm on pre-commit-ci-update-config

    (compare)

  • Jan 03 19:48

    agronholm on master

    [pre-commit.ci] pre-commit auto… (compare)

  • Jan 03 19:48
    agronholm closed #586
  • Jan 03 17:47

    pre-commit-ci[bot] on pre-commit-ci-update-config

    [pre-commit.ci] pre-commit auto… (compare)

  • Jan 03 17:47
    pre-commit-ci[bot] opened #586
Alex Grönholm
@agronholm
what's the problem?
what are you trying to accomplish?
Vioshim
@Vioshim
Hello people, I've been testing the master branch, and realized that AsyncIOScheduler isn't there, is that module getting removed, deprecated or something?
Alex Grönholm
@agronholm
@Krangelj there are two schedulers now, AsyncScheduler and SyncScheduler
you want to use AsyncScheduler
Vioshim
@Vioshim
Oh I see, all right I'll try to check how that one works, seems it doesn't use .start()
Alex Grönholm
@agronholm
I suggest you look at the tests because the docs haven't been updated yet
Vioshim
@Vioshim

Made some small changes in my code and now it works as usual, basically add_schedule rather than add_job along with not having to make a .start()

But, thanks it worked.

Alex Grönholm
@agronholm
:thumbsup:
Vioshim
@Vioshim
image.png

Morning

also btw, is there a way to use an AsyncScheduler without using async with ?

I was randomly play testing and discovered that this is apparently the only way to replicate old .start() behavior

Alex Grönholm
@agronholm
it is currently the only way – if you have a convincing case against it, please present it so I can take that into account in the design
Vioshim
@Vioshim

I see, well I work on a discord bot (chat bot), in which it executes itself in a different loop, then in commands, we usually add events to make the bot keep executing those Scheduler functions without interrupting the main execution, hence why in my code I can't use the async with due to it being functions that make callbacks to existing elements.

For example, in the older Apscheduler, this is how I used to do stuff there

Alex Grönholm
@agronholm
where are you starting the scheduler?
Vioshim
@Vioshim
I'll fix the pic, it has some issues ^^;
Alex Grönholm
@agronholm
(btw that if condition can't work right...)
Vioshim
@Vioshim
ye that
image.png
Alex Grönholm
@agronholm
no matter what, the scheduler start will be asynchronous
regardless of whether its use as an async context manager is enforced
so this won't work
Vioshim
@Vioshim
Ye Ik, I was referring about how it used to be done in the past, that's why I was recommending adding a start() asynchronous which works and allows to add/execute functions without it occurring in aenter
Alex Grönholm
@agronholm
yeah but if you do that, what's preventing you from using it as an async context manager?
Vioshim
@Vioshim

Well, mostly by the fact that I can't add schedulers or execute them within an async context manager, due to the main loop executing and making function calls in order to add the scheduled tasks

• Bot runs
• Scheduler executing
• Bot's commands invoke .add_schedule() within functions, and I can't really keep a while True loop open in a command in order to keep a Scheduler executing ^^;

Alex Grönholm
@agronholm
why not keep a task open for that then?
Vioshim
@Vioshim

Well yeah, and that's what I'm doing atm with the

scheduler.__aenter__()

Doing that keeps it open until I use .stop()

Alex Grönholm
@agronholm
do you have your entire project in a public repo?
Vioshim
@Vioshim
No, however I can make a small test repo to show it
Alex Grönholm
@agronholm
that might be helpful
Vioshim
@Vioshim
Awesome, in that case I'll brb, thanks for the help & support btw
Alex Grönholm
@agronholm
:ok_hand:
Vioshim
@Vioshim

Alright here it is

I made the repo by making a small bot example which replies to a message from an user 10 seconds after

https://github.com/Krangelj/ScheduleBot_test.git

Alex Grönholm
@agronholm
ok the fundamental problem here is that the Bot class was not designed with async programming in mind
much like the old AsyncIOScheduler
@Krangelj if I understand correctly, the async aspect of Bot is just an implementation detail, yes?
Vioshim
@Vioshim

Well, according to discord py, it is intended to be

A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.

In which the async aspect of the bot, is mostly about how it works and how it handles API events

Alex Grönholm
@agronholm
is it possible to run the bot in an asyncio task?
or does it insist on running its own event loop?
Vioshim
@Vioshim

Well, bot.run is gonna be deprecated,

bot.start(token) is a coroutine which requires a asyncio.run

but right now bot.run(token) == asyncio.run(bot.start(token))

Alex Grönholm
@agronholm
then it's all good
you just need to use that syntax instead
do you know what to do?
Vioshim
@Vioshim

Well, I kinda do but I mean, right now, using each syntax doesn't truly make a difference on the main.py

The Apscheduler part it's the one at cogs/daily_question.py which has the .__aenter__() approach

Alex Grönholm
@agronholm
you can start the scheduler in main.py
Vioshim
@Vioshim
Oh interesting, but wouldn't it close if I do async with?
Alex Grönholm
@agronholm
bot.start() will block indefinitely, won't it?
Vioshim
@Vioshim

Ye it should,

But Oh yeah, that's a quite interesting approach, and possibly I can get to add that scheduler as an attribute to the bot class in order to access it in commands,

thanks for the help.

Marco Antonio
@mgrazianoc
image.png
whats up fols