Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't work with multi threads and jupyter #41

Closed
lucasccampos opened this issue Jul 31, 2022 · 2 comments
Closed

Don't work with multi threads and jupyter #41

lucasccampos opened this issue Jul 31, 2022 · 2 comments

Comments

@lucasccampos
Copy link

running Multicall in main thread works great, but running the function twice in another thread is going to throw an error

"RuntimeError: Timeout context manager should be used inside a task"

and when using Multicall with jupyter, u get this error

File ~/.local/lib/python3.10/site-packages/multicall/multicall.py:57, in Multicall.call(self)
55 def call(self) -> Dict[str,Any]:
56 start = time()
---> 57 response = await_awaitable(self.coroutine())
58 logger.debug(f"Multicall took {time() - start}s")
59 return response

File ~/.local/lib/python3.10/site-packages/multicall/utils.py:67, in await_awaitable(awaitable)
66 def await_awaitable(awaitable: Awaitable) -> Any:
---> 67 return get_event_loop().run_until_complete(awaitable)

File /usr/lib64/python3.10/asyncio/base_events.py:622, in BaseEventLoop.run_until_complete(self, future)
611 """Run until the Future is done.
612
613 If the argument is a coroutine, it is wrapped in a Task.
(...)
619 Return the Future's result, or raise its exception.
620 """
621 self._check_closed()
--> 622 self._check_running()
624 new_task = not futures.isfuture(future)
625 future = tasks.ensure_future(future, loop=self)

File /usr/lib64/python3.10/asyncio/base_events.py:582, in BaseEventLoop._check_running(self)
580 def _check_running(self):
581 if self.is_running():
--> 582 raise RuntimeError('This event loop is already running')
583 if events._get_running_loop() is not None:
584 raise RuntimeError(
585 'Cannot run the event loop while another loop is running')

RuntimeError: This event loop is already running

@cheekybastard
Copy link

cheekybastard commented Sep 20, 2022

latest multicall works with jupyter if you install: https://github.com/erdewit/nest_asyncio

in the jupyter cell add:

import nest_asyncio
nest_asyncio.apply()

@BobTheBuidler
Copy link
Collaborator

multithread issue is fixed if you use web3>=5.31.3

Jupyter issue is related to jupyter event loop and solution has been shared above. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants