Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 14 18:46
    agronholm commented #562
  • Oct 14 18:46
    agronholm closed #562
  • Oct 14 18:02
    TCVZ labeled #562
  • Oct 14 18:02
    TCVZ opened #562
  • Oct 14 15:59
    agronholm closed #560
  • Oct 14 15:59
    agronholm locked #560
  • Oct 14 15:57
    agronholm labeled #560
  • Oct 14 15:56
    alxfed opened #560
  • Oct 13 09:43
    agronholm commented #559
  • Oct 13 09:40
    radiantone opened #559
  • Oct 13 09:38
    radiantone edited #558
  • Oct 13 09:37
    radiantone opened #558
  • Oct 13 09:36
    radiantone opened #557
  • Oct 13 09:33
    iamliamc commented #556
  • Oct 13 09:33
    iamliamc commented #556
  • Oct 13 09:20
    agronholm commented #556
  • Oct 13 09:11
    iamliamc commented #556
  • Oct 13 09:11
    iamliamc commented #556
  • Oct 13 08:58
    iamliamc commented #556
  • Oct 13 08:44
    agronholm commented #556
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
folks*
im learning just now this incredible library
but im having some difficulties to understand some concepts
one of them is about scheduled jobs and what one job must need to be scheduled
in this example I made on main loop of asyncio, one job what scheduled to happend soon, while other 60 of them would happen every minute after a while
the idea was to just see how the library talks to postgres
the times were all correct, the table TEST were created on the database, but none of the tasks were stored there, which got me confused
Marco Antonio
@mgrazianoc
as tasks comes to the scheduler, shouldn't it immediately save it on the database?
Marco Antonio
@mgrazianoc
not only that, when print_jobs is called, it says "no scheduled jobs"
using debug mode, i think i got a clue of what is happening: "INFO:apscheduler.scheduler:Added job "simple_job" to job store "default""
it sent to default store when i should sent it to my store, hmmm
Marco Antonio
@mgrazianoc
I now suspect it has something to do with being async?
Alex Grönholm
@agronholm
@mgrazianoc if you don't specify the store to save it to, it goes to default
if you want all jobs to go to postgres, you should name it default
Alex Grönholm
@agronholm
also I'm not seeing you start an asyncio event loop anywhere
if you don't want an asyncio event loop, why use AsyncIOScheduler?
Marco Antonio
@mgrazianoc
oh, thanks for the reply
there's a call of asyncio below the print, asyncio.get_event_loop().run_forever()
for some odd reason, I thought that naming it "postgres" would do the job, but it does makes sense to save it as default, since we are ovewriting it
i'm gonna test it today
this library is really good