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

axon threads and exception handling [merge conflict fixed] #2459

Open
wants to merge 14 commits into
base: staging
Choose a base branch
from

Conversation

thewhaleking
Copy link
Contributor

Fixed merge conflicts in #2227

opendansor and others added 10 commits August 29, 2024 11:24
Various issues were encountered trying to run and understand e2e tests:
- if uvicorn fails to start, an uncaught exception is emitted to stderr
- axon keeps spinning waiting for self.started, indefinitely
- exceptions are not propagated from threads
- there is no way to (simply) test from the outside whether an axon
  started and/or runs
- axon creates a thread that only creates another thread, which seems
  redundant

This patch addresses some of these issues, in FastAPIThreadedServer:
- add thread safe set/get_exception() to set/get exceptions
- run_in_thread() yields the created thread, so that the code using it
  can check whether the thread is alive
- uvicorn.Server.startup() is wrapped to set a thread-safe flag using
  self.set_started(True) to indicate startup succeeded
- run_in_thread() times out after one second to prevent infinite loop in
  case self.get_started() never becomes True
- run_in_thread() raises an exception if it fails to start the thread
- _wrapper_run() tests whether the thread is still alive

and in class axon, the following are added:
- @Property axon.exception(), returning any exception
- axon.is_running(), returning True when the axon is operational

The seemingly redundant thread is left in until feedback is received on
the reasons for including it.
- ruff formatting
- docstrings
- variable names
- type annotations
- don't return ret = startup() which is annotated to return None
- moved time sleep intervals to singular global, for clarity
…after pip install

Although it seems common to have types.py (e.g. scalecodec, torch,
substrateinterface) this may lead to issues after applying pip install
-e to a package, as is suggested for bittensor (see git grep 'pip
install -e.* bittensor')

Issues were observed where circular imports would arise as Python's
native typing.py would include bittensor's types.py.
…n-threads-and-exception-handling

# Conflicts:
#	bittensor/bt_types.py
#	bittensor/commands/stake.py
#	bittensor/core/axon.py
#	bittensor/core/types.py
#	bittensor/subtensor.py
#	bittensor/types.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants