#async init

1 messages · Page 1 of 1 (latest)

elfin rune
#

a class __init__?

#

you don't.

#

OK?

#

Explain what you're trying to do and show code.

#

Then just do self.session = aiohttp.ClientSession(...)
and use that session in your async requests methods

placid mason
#

You don't create a session in init

elfin rune
placid mason
#

You can pass it from outside

elfin rune
#

Or that ^

placid mason
#
async def main():
    async with aiohttp.ClientSession() as session:
        bot = ChatBot(..., session=session)
        ...
        await bot.run()
#

This ensures the session will be closed when the bot quits etc etc

#

How do you run your bot

#

Why is that relevant

#

Your problem is obtaining an async resource during initialization
How's what you posted relevant to the problem