GoogleCloudPlatform / cloud-profiler-python

Stackdriver Profiler Python agent is a tool that continuously gathers CPU usage information from Python applications
Apache License 2.0
28 stars 23 forks source link

Errors out on import #80

Closed jhorowitz closed 3 years ago

jhorowitz commented 3 years ago

I receive the following error when I try to import the profiler. I tested several version of the profiler and the issue appears to start at version 3.0.0 of the profiler. I did not have the issue with 2.0.6

System Information:

Error: ImportError: cannot import name '_profiler' from partially initialized module 'googlecloudprofiler' (most likely due to a circular import)

wyk9787 commented 3 years ago

Thanks for reporting this.

Unfortunately, we don't officially support macOS due to limited capacity. You can find this information here. I will update the README on this repo shortly.

With that being said, the reason it stopped working starting from version 3.0.0 is we removed check whether it's Linux before importing the CPU profiler in https://github.com/GoogleCloudPlatform/cloud-profiler-python/pull/76/files.

You have two options if you want to keep using the Cloud Profiler on macOS (there is no guarantee the newer version will keep working):

  1. You can add cpu_profiler = None and removed from googlecloudprofiler import cpu_profiler in the source file client.py.
  2. You can keep using version 2.0.6. The version 3.0.0 essentially drops the support for Python prior to 3.6 (since you are using Python 3.8, it shouldn't matter).

Sorry about the inconvenience!

jhorowitz commented 3 years ago

Thanks for the explanation! Makes perfect sense.

Quick suggestion: It would be nice if the import alone did not crash the app on an unsupported os. I think it would make more sense to raise an error when a method which uses an unavailable lib is called. Just my point of view, not a criticism of your design choices!

wyk9787 commented 3 years ago

@jhorowitz We decided to push out a new release 3.0.3 that fixes the issue; it's an easy fix and probably we shouldn't break on import even if macOS is not officially supported :)

You should be able to update your google-cloud-profiler to 3.0.3 to solve the issue. Thanks!