miguelgfierro/ai_projects

Error in Intro_to_Cloud_ML_with_Flask_and_CNTK.ipynb TypeError: Use async with instead

shirishr opened this issue · 3 comments

current version of aiohttp is 3.3.0
I suspect that because of this, the notebook encounters errors.
The moment with aiohttp.ClientSession() as session: is executed, it results in error TypeError: Use async with instead

The version I used for this notebook was aiohttp==2.0.3, could you try with that?

@miguelgfierro,

I know I am being greedy :o)
The code so far has certainly shown how to build a production-worthy setup.
However persisting with this for the sake of completeness

Uninstalled aiohttp and reinstalled aiohttp==2.0.3

but got a new error

RuntimeError: This event loop is already running

Full trace:


RuntimeError Traceback (most recent call last)
in ()

~/anaconda3/envs/mxnet/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
453 future.add_done_callback(_run_until_complete_cb)
454 try:
--> 455 self.run_forever()
456 except:
457 if new_task and future.done() and not future.cancelled():

~/anaconda3/envs/mxnet/lib/python3.6/asyncio/base_events.py in run_forever(self)
407 self._check_closed()
408 if self.is_running():
--> 409 raise RuntimeError('This event loop is already running')
410 if events._get_running_loop() is not None:
411 raise RuntimeError(

RuntimeError: This event loop is already running

Update

There are some other messages but not in trace as:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<run_experiment() done, defined at :21> exception=RuntimeError('Session is closed',)>
Traceback (most recent call last):
File "", line 30, in run_experiment
data = yield from future
File "/home/sam/anaconda3/envs/mxnet/lib/python3.6/asyncio/tasks.py", line 458, in _wait_for_one
return f.result() # May raise f.exception().
File "", line 14, in http_get
response = yield from s.request('post', url, data=img)
File "/home/sam/anaconda3/envs/mxnet/lib/python3.6/site-packages/aiohttp/client.py", line 616, in iter
resp = yield from self._coro
File "/home/sam/anaconda3/envs/mxnet/lib/python3.6/site-packages/aiohttp/client.py", line 164, in _request
raise RuntimeError('Session is closed')
RuntimeError: Session is closed

hey @shirishr I added a conda file with the library version that I used one year ago when I did this example. I hope that fixes your error and unblocks you.

I tried to run the notebook again but I found some breaking changes from CNTK and others, that unfortunatelly, I don't have time to fix now.

I would recommend to use this tutorial as a base point for what you want to build, and not take the code as it is, since it is breaking right now.

Good luck!