RuntimeError: There is no current event loop in thread in flask?

Why I am getting this error When I run my code?

Actually I want to run when I start my flask app and should be callable in background after every 10 second

import asyncio
import aiohttp
from database import DBHelper

MESSAGE_TO_SEND = 'Please Complete Your Task'
ACCESS_TOKEN = access_token

db = DBHelper()

async def taskReminder(memberID):
    data = {
        "recipient": { "id": memberID },
        "message": { "text": MESSAGE_TO_SEND }
    async with aiohttp.ClientSession() as session:
        async with""+ ACCESS_TOKEN, json=data) as response:
            return await response.text()

def main():

    loop = asyncio.get_event_loop()

    Members = db.loadMembersNotCompletedTask()
    coroutines = [taskReminder(''.join(member)) for member in Members]

from flask import Flask, request,render_template
from apscheduler.schedulers.background import BackgroundScheduler
from autoreminder import main

app = Flask(__name__)

scheduler = BackgroundScheduler()
job = scheduler.add_job(main, 'interval', seconds=10)

# Starting app
if __name__ == "__main__":


RuntimeError: There is no current event loop in thread 'ThreadPoolExecutor-0_0'.

Read more here:

Content Attribution

This content was originally published by Bhavesh Mevada at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: