Skip to content

Commit

Permalink
Merge branch 'main' into feat/collective_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jul 17, 2023
2 parents c5d1496 + a7c94f7 commit e9394fc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions python/xoscar/_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,23 @@ cdef class TypeDispatcher:
cdef _reload_lazy_handlers(self):
for k, v in self._lazy_handlers.items():
mod_name, obj_name = k.rsplit('.', 1)
with warnings.catch_warnings():
# the lazy imported cudf will warn no device found,
# when we set visible device to -1 for CPU processes,
# ignore the warning to not distract users
warnings.simplefilter("ignore")
mod = importlib.import_module(mod_name, __name__)
self.register(getattr(mod, obj_name), v)
imported = False
try:
with warnings.catch_warnings():
# the lazy imported cudf will warn no device found,
# when we set visible device to -1 for CPU processes,
# ignore the warning to not distract users
warnings.simplefilter("ignore")
mod = importlib.import_module(mod_name, __name__)
imported = True
# The reason all exceptions are caught here instead of ImportError is that
# when, for example, a cpu machine tries to import cuda, the exception thrown is CudaAPIError.
except: # pragma: no cover
imported = False
warnings.warn(f'Import {mod_name} failed. Please check your current Python environment.')

if imported:
self.register(getattr(mod, obj_name), v)
self._lazy_handlers = dict()

cpdef get_handler(self, object type_):
Expand Down

0 comments on commit e9394fc

Please sign in to comment.