python - How to debug an import statement changing behavior -
I have a script that I was trying to add to signal handler for ctr-c, something before exiting To the final handling.
It's own, it works fine, but as soon as I try in my program, it does not work. Adding or removing an import varies behavior.
Without P4 API imports, it expects I hope. If I import the P4 API, the CTR-C asks to exit or bypass my handler, and I'm not sure why,
Import sign import time import sys # - Commented on this, things work #import P4API def run_program (): While this is true: time.sleep (1) print ("a") def exit_gracefully (Signum, Frame): # Not to mention the original signal handler signal, otherwise the bad things will be # in raw_input when CTRL + C is pressed, and our signal Try Andlr no entrant again signal.signal (.SIGINT, original_sigint): If raw_input ( "? \ Nreally leave (y / n) & gt;") .lower () startswith ( 'y') :. Sys.exit (1) except the KeyboardInterrupt: print ("OK OK signal.SIGINT # store original SIGINT handler original_sigint = signal.getsignal (, leaving") sys.exit (1) # exit restored gracefully here handler signal Signal.signal (signal sign, exit_gracefully) run_program ()
, p4api calls a class signal
that it uses" to deal with the disruption ":
Prompt the
class enables API Programmers are asked to register the functions that receive an interval signal client application. TheSignaler
class keeps a list of registered functions and calls each one.After all registered functions are executed, the process is finished, -1 returns to the operating system.
It is possible that when you import import p4api
, your signal handler is interfering with its signal handler, and in the end this signal is theft and Calling _exit (-1)
or similarly before you get a chance to do anything useful.
You can find the details, but it seems that the code is the C ++ name of the signaller :: onent
function that you want to call to register with your signal handler. . There is also an example code in Docs. I first gives Google search results, which makes it clear that it is correct.
I do not see anything, and I do not know that there is a cover around the Python API C ++ API, or a different implementation, but the way I'm guessing it has one A class with the same name that is to be used in the same way.
Comments
Post a Comment