Splunk Dev

How to reload changed python code without restarting Splunk?

arjitg
Explorer

Hi All , My query was is there any way we can reload the changed python script without restarting the splunk everytime? 

I understand we have _bump for javascript and CSS & debug/refresh for .conf files but do we have a similiar command for changed python scripts as well?

Thanks & Regards

AG.  

Labels (3)
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Please describe your use case.  I change the Python code in my apps often and never need to restart Splunk.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

dhaparam
Engager

Try adding this line at the top of your python script. This will not store cached script

Only in dev

import datetime;print(datetime.datetime.now())
0 Karma

AgentTimon
Engager

You need to "Disable the client and server caches during development".

https://dev.splunk.com/enterprise/docs/developapps/manageknowledge/assetcaching/

Dohrendorf_Cons
Path Finder

I have the same problem. 

To specify it a little further: 

I am developing a custom REST Endpoint using 

from splunk.persistconn.application import PersistentServerConnectionApplicationPython

When I run the endpoint I get the expected result. However if I then go on to change the code, the changes sometimes impact the output and sometimes they don't no matter what I do to the code. Even if I deliberately break the code, the endpoint still works.

As far as I could figure out, I have about 5-10 iterations that will impact the output, afterwards some cached version of my script seems to be executed. If I reach that point, the only thing, that makes new versions of the code show up, is restarting splunk, as initially suggested.

So if there is something similar to _bump or debug/refresh for Python, that would be a HUGE help.

I have experienced this behavior with Splunk 6, 7, and 8. Previous versions I have not done much development on, so I can't say.

Any suggestions would be immensely appreciated.

 

 

0 Karma

Funderburg78
Path Finder

Even better question, I recently learned python, how do I take what I learned and use it in splunk?  Explanation links to articles are fine answers!  Yes, I give Karma!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Please ask a new question rather than hijack a thread.

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Please describe your use case.  I change the Python code in my apps often and never need to restart Splunk.

---
If this reply helps you, Karma would be appreciated.

arjitg
Explorer

Hi @richgalloway ! Thanks for this. So does it mean that you don't have to restart the Splunk server whenever you make any changes to your python code in "bin" folder? You can save the code and it should run fine whenever we are triggering this code through JS ? 

In my use case, I am trying to encrypt password using python script. My JS is calling this python script &  sending that encrypted password  to Splunk to display.

Thanks

AG.  

 

  

0 Karma
Get Updates on the Splunk Community!

Developer Spotlight with Paul Stout

Welcome to our very first developer spotlight release series where we'll feature some awesome Splunk ...

State of Splunk Careers 2024: Maximizing Career Outcomes and the Continued Value of ...

For the past four years, Splunk has partnered with Enterprise Strategy Group to conduct a survey that gauges ...

Data-Driven Success: Splunk & Financial Services

Splunk streamlines the process of extracting insights from large volumes of data. In this fast-paced world, ...