jerrypeng commented on a change in pull request #2847: Cleanup Logging for
python functions
URL: https://github.com/apache/pulsar/pull/2847#discussion_r228338856
##########
File path: pulsar-functions/instance/src/main/python/util.py
##########
@@ -36,38 +36,33 @@
def import_class(from_path, full_class_name):
from_path = str(from_path)
full_class_name = str(full_class_name)
- kclass = import_class_from_path(from_path, full_class_name)
- if kclass is None:
+ try:
+ return import_class_from_path(from_path, full_class_name)
+ except Exception as e:
our_dir =
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
api_dir = os.path.join(our_dir, PULSAR_API_ROOT, PULSAR_FUNCTIONS_API_ROOT)
- kclass = import_class_from_path(api_dir, full_class_name)
- return kclass
+ try:
+ return import_class_from_path(api_dir, full_class_name)
+ except Exception as e:
+ Log.info("Failed to import class %s from path %s" % (full_class_name,
from_path))
+ Log.info(e, exc_info=True)
+ return None
def import_class_from_path(from_path, full_class_name):
- Log.info('Trying to import %s from path %s' % (full_class_name, from_path))
+ Log.debug('Trying to import %s from path %s' % (full_class_name, from_path))
split = full_class_name.split('.')
classname_path = '.'.join(split[:-1])
class_name = full_class_name.split('.')[-1]
if from_path not in sys.path:
- Log.info("Add a new dependency to the path: %s" % from_path)
+ Log.debug("Add a new dependency to the path: %s" % from_path)
sys.path.insert(0, from_path)
if not classname_path:
- try:
- mod = importlib.import_module(class_name)
- return mod
- except Exception as e:
- Log.info("Import failed class_name %s from path %s" % (class_name,
from_path))
- Log.info(e, exc_info=True)
- return None
+ mod = importlib.import_module(class_name)
Review comment:
didn't this throw an exception before and we catch it and when to do print.
If we don't do the try and except, wouldn't it crash the function instance?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services