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

Fixes --profile parameter #1967

Merged
merged 1 commit into from Jun 9, 2019
Merged

Fixes --profile parameter #1967

merged 1 commit into from Jun 9, 2019

Conversation

danirod
Copy link
Contributor

@danirod danirod commented Aug 16, 2018

While attempting to debug some issue we found in our environment, I tried to make use of the --profile flag of shinken-broker. Unfortunately, this feature is broken because the context in which shinken runs doesn't have access to local or global variables, so this error is spit out:

Traceback (most recent call last):                                                  
  File "bin/shinken-poller", line 99, in <module>
    main()                                                                          
  File "bin/shinken-poller", line 95, in main
    cProfile.run('''daemon.main()''', opts.profile)                                                                                                                                              
  File "/usr/lib/python2.7/cProfile.py", line 29, in run                                                                                                                                         
    prof = prof.run(statement)                       
  File "/usr/lib/python2.7/cProfile.py", line 135, in run
    return self.runctx(cmd, dict, dict)
  File "/usr/lib/python2.7/cProfile.py", line 140, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
NameError: name 'daemon' is not defined

This PR uses cProfile.runctx instead of cProfile.run in order to provide cProfile our locals and our globals so that it finds the daemon and is able to spawn a profile environment. It fixes this error.

cProfile calls daemon.main() without globals and locals information,
therefore the call fails because the cProfile context where the line is
run does not know what is daemon.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.005%) to 27.725% when pulling 968c1ca on danirod:fixes-cprofile into a8c8ec9 on naparuba:master.

@naparuba
Copy link
Contributor

naparuba commented Jun 9, 2019

Thanks for the fix and sorry about the (long) delay.

@naparuba naparuba merged commit a6d369a into shinken-solutions:master Jun 9, 2019
mohierf pushed a commit to mohierf/shinken that referenced this pull request Dec 3, 2019
cProfile calls daemon.main() without globals and locals information,
therefore the call fails because the cProfile context where the line is
run does not know what is daemon.
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

Successfully merging this pull request may close these issues.

None yet

3 participants