python - Modify interior of a looping function at runtime -


this one's doozy, bear me.

i'm calling in library has function waits indefinitely kind of input. unfortunately, function bugged in such way allows pipeline reads fill irrelevant input, causing program lock waits input has blinded to. library entirely critical, exceptionally difficult replicate, , maintainer not accepting pull requests or bug reports.

i need inject "flush pipe" function call body of function. i've solved problem taking advantage of similar functions having callback parameters, specific function has no such parameter.

what can do?

it seems can view source code can go through source code , locate method called inside bugged method , monkey patch it:

class otherguysclass:      def buggedmethod(self, items):         item in items:             = self.convert(item)             print(a * 5)      def convert(self, str):         return int(str)  if __name__ == "__main__":     try:         otherguysclass().buggedmethod([1, 2, none, 5])     except exception e:         print("bugged method crashed: " + str(e))      # replace convert our own method returns 0 none , ""     o = otherguysclass()     original_convert = o.convert     def float_convert(str):         if str:             return original_convert(str)         return 0     o.convert = float_convert     o.buggedmethod(["1", "2", none, "5"]) 

5
10
bugged method crashed: int() argument must string, bytes-like object or number, not 'nonetype'
5
10
0
25


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -