Following code is a boiler plate code with asyncio in python to fetch response from urls. This code works fine in mac with python 3.7 but in windows 10 with python 3.8, it doesn't reach the "in here" print statement. Any clues on why that is so and how it can be fixed in windows?
def Initiate(list, folder_week, xmlfile, csvfile):
bap = BAPRequest(folder_week, xmlfile, csvfile)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
future = loop.create_future()
future = asyncio.ensure_future(bap.run(list, True))
loop.run_until_complete(future)
loop.close()
async def fetch(self, url, incident, session, csv):
async with session.get(url) as response:
**print("in here")**
self.format_output(await response.read())
async def bound_fetch(self, sem, url, incident, session, csv):
async with sem:
return await self.fetch(url, incident, session, csv)
async def run(self, r, csv):
url = self.conversations_url
tasks = []
sem = asyncio.Semaphore(1000)
sslcontext = ssl.create_default_context(cafile=certifi.where())
sslcontext.load_cert_chain('./cert/certificate.pem',
'./cert/plainkey.pem')
async with ClientSession(connector=aiohttp.TCPConnector(ssl=sslcontext, force_close=True)) as session:
for i in r:
# pass Semaphore and session to every GET request
task = asyncio.ensure_future(self.bound_fetch(sem, url + str(i), i, session, csv))
tasks.append(task)
await asyncio.gather(*tasks, return_exceptions=True)
await session.close()
return "Done"