How to stop a repeating error message or figure out where it is coming from
I am working with some python code, which is quite complex (for me at least). There are many objects and modules and functions that call other functions etc.
When I run the code, sometimes something goes wrong. (It makes sense that it doesn't always go wrong, because it involves sampling and random number etc..)
When the code goes wrong, it doesn't crash, but I'm getting an output repeated ad infinitum (it may stop if I left it long enough):
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
.
.
I can't seem to figure out which of the many imported modules is producing this message. I'm not even sure at what point in the code this is happening because any other output is lost from the screen. I don't want to read all output into a text file, because the code runs a long time before it does or doesn't fail and the file will be very large I guess.
Is there any way that I can get my code to break as soon as it starts spitting out this Diagonal element of covariance matrix = 0
message. Then I could at least figure out where in the code the problem is occuring.
Any other ideas welcome too!
python
add a comment |
I am working with some python code, which is quite complex (for me at least). There are many objects and modules and functions that call other functions etc.
When I run the code, sometimes something goes wrong. (It makes sense that it doesn't always go wrong, because it involves sampling and random number etc..)
When the code goes wrong, it doesn't crash, but I'm getting an output repeated ad infinitum (it may stop if I left it long enough):
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
.
.
I can't seem to figure out which of the many imported modules is producing this message. I'm not even sure at what point in the code this is happening because any other output is lost from the screen. I don't want to read all output into a text file, because the code runs a long time before it does or doesn't fail and the file will be very large I guess.
Is there any way that I can get my code to break as soon as it starts spitting out this Diagonal element of covariance matrix = 0
message. Then I could at least figure out where in the code the problem is occuring.
Any other ideas welcome too!
python
1
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
1
if it's a cli, try usingpython -m trace ...
:docs.python.org/2/library/trace.html
– teng
Nov 24 '18 at 2:18
add a comment |
I am working with some python code, which is quite complex (for me at least). There are many objects and modules and functions that call other functions etc.
When I run the code, sometimes something goes wrong. (It makes sense that it doesn't always go wrong, because it involves sampling and random number etc..)
When the code goes wrong, it doesn't crash, but I'm getting an output repeated ad infinitum (it may stop if I left it long enough):
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
.
.
I can't seem to figure out which of the many imported modules is producing this message. I'm not even sure at what point in the code this is happening because any other output is lost from the screen. I don't want to read all output into a text file, because the code runs a long time before it does or doesn't fail and the file will be very large I guess.
Is there any way that I can get my code to break as soon as it starts spitting out this Diagonal element of covariance matrix = 0
message. Then I could at least figure out where in the code the problem is occuring.
Any other ideas welcome too!
python
I am working with some python code, which is quite complex (for me at least). There are many objects and modules and functions that call other functions etc.
When I run the code, sometimes something goes wrong. (It makes sense that it doesn't always go wrong, because it involves sampling and random number etc..)
When the code goes wrong, it doesn't crash, but I'm getting an output repeated ad infinitum (it may stop if I left it long enough):
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
Diagonal element of covariance matrix = 0
.
.
I can't seem to figure out which of the many imported modules is producing this message. I'm not even sure at what point in the code this is happening because any other output is lost from the screen. I don't want to read all output into a text file, because the code runs a long time before it does or doesn't fail and the file will be very large I guess.
Is there any way that I can get my code to break as soon as it starts spitting out this Diagonal element of covariance matrix = 0
message. Then I could at least figure out where in the code the problem is occuring.
Any other ideas welcome too!
python
python
asked Nov 24 '18 at 1:58
user1551817user1551817
1,30292954
1,30292954
1
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
1
if it's a cli, try usingpython -m trace ...
:docs.python.org/2/library/trace.html
– teng
Nov 24 '18 at 2:18
add a comment |
1
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
1
if it's a cli, try usingpython -m trace ...
:docs.python.org/2/library/trace.html
– teng
Nov 24 '18 at 2:18
1
1
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
1
1
if it's a cli, try using
python -m trace ...
:docs.python.org/2/library/trace.html– teng
Nov 24 '18 at 2:18
if it's a cli, try using
python -m trace ...
:docs.python.org/2/library/trace.html– teng
Nov 24 '18 at 2:18
add a comment |
1 Answer
1
active
oldest
votes
While I am not happy to say it, your best bet may be using some kind of timer to kill the function's execution. For example, you could put something like this in your code to kill the function and then attempt to either generate a new random matrix, or attempt to fix the covariance matrix manually.
import time
import signal
def black_box():
while True:
print("Diagonal element of covariance matrix = 0")
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5) # Upper bound of execution normal time
try:
black_box()
except Exception:
# Handle timeout
pass
signal.pause()
Best of luck...
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to thesignal.pause()
line, the error will be thrown. Killing the code.
– The Pineapple
Nov 24 '18 at 17:24
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454560%2fhow-to-stop-a-repeating-error-message-or-figure-out-where-it-is-coming-from%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
While I am not happy to say it, your best bet may be using some kind of timer to kill the function's execution. For example, you could put something like this in your code to kill the function and then attempt to either generate a new random matrix, or attempt to fix the covariance matrix manually.
import time
import signal
def black_box():
while True:
print("Diagonal element of covariance matrix = 0")
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5) # Upper bound of execution normal time
try:
black_box()
except Exception:
# Handle timeout
pass
signal.pause()
Best of luck...
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to thesignal.pause()
line, the error will be thrown. Killing the code.
– The Pineapple
Nov 24 '18 at 17:24
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
|
show 7 more comments
While I am not happy to say it, your best bet may be using some kind of timer to kill the function's execution. For example, you could put something like this in your code to kill the function and then attempt to either generate a new random matrix, or attempt to fix the covariance matrix manually.
import time
import signal
def black_box():
while True:
print("Diagonal element of covariance matrix = 0")
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5) # Upper bound of execution normal time
try:
black_box()
except Exception:
# Handle timeout
pass
signal.pause()
Best of luck...
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to thesignal.pause()
line, the error will be thrown. Killing the code.
– The Pineapple
Nov 24 '18 at 17:24
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
|
show 7 more comments
While I am not happy to say it, your best bet may be using some kind of timer to kill the function's execution. For example, you could put something like this in your code to kill the function and then attempt to either generate a new random matrix, or attempt to fix the covariance matrix manually.
import time
import signal
def black_box():
while True:
print("Diagonal element of covariance matrix = 0")
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5) # Upper bound of execution normal time
try:
black_box()
except Exception:
# Handle timeout
pass
signal.pause()
Best of luck...
While I am not happy to say it, your best bet may be using some kind of timer to kill the function's execution. For example, you could put something like this in your code to kill the function and then attempt to either generate a new random matrix, or attempt to fix the covariance matrix manually.
import time
import signal
def black_box():
while True:
print("Diagonal element of covariance matrix = 0")
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5) # Upper bound of execution normal time
try:
black_box()
except Exception:
# Handle timeout
pass
signal.pause()
Best of luck...
edited Nov 24 '18 at 2:16
answered Nov 24 '18 at 2:08
The PineappleThe Pineapple
408312
408312
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to thesignal.pause()
line, the error will be thrown. Killing the code.
– The Pineapple
Nov 24 '18 at 17:24
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
|
show 7 more comments
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to thesignal.pause()
line, the error will be thrown. Killing the code.
– The Pineapple
Nov 24 '18 at 17:24
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
1
1
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
@user1551817 Definitely! It is essentially the python equivalent of a Watchdog Timer. These timers are super common in hardware. Essentially, if the timer is not reset due to abnormally long execution, it is treated as an error. Therefore, you can handle it differently than the normal execution, and do something else or reset.
– The Pineapple
Nov 24 '18 at 3:27
1
1
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
@user1551817 This methodology isn't very common in non-hardware interfacing code, because it is usually debug-able. Compared to a device operating in an environment, where it is general not feasible or practical to debug.
– The Pineapple
Nov 24 '18 at 3:30
1
1
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
@user1551817 I just just put that in the example as an illustration of how it works just in case you wanted to test the code before merging it into your code base. As you can see when the example is run it would normally never exit unless killed. But given the signal stuff it will finish after ~5 seconds.
– The Pineapple
Nov 24 '18 at 3:32
1
1
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to the
signal.pause()
line, the error will be thrown. Killing the code.– The Pineapple
Nov 24 '18 at 17:24
@user1551817 You can just put the code that is causing issues in the try part of the try-catch block. the black_box function I created was just to illustrate the problem you were having since in theory the function example I gave spits out that message and never exits. The error is thrown when the signal is timer has not been reset or paused within the five second time frame. It is completely independent of your code. Given that your code blocks the program occasionally for a significant period of time, thus not getting to the
signal.pause()
line, the error will be thrown. Killing the code.– The Pineapple
Nov 24 '18 at 17:24
1
1
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
@user1551817 Its all good. Signals are a weird thing. I also made a gif of this in action with some added inline explanation to better show how it works.
– The Pineapple
Nov 24 '18 at 17:58
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454560%2fhow-to-stop-a-repeating-error-message-or-figure-out-where-it-is-coming-from%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you are unable to search the code for the line responsible for that warning print out, then I recommend using an ide (pycharm) and run the code in debugger mode, hit pause once the warning starts to print out.
– teng
Nov 24 '18 at 2:02
1
if it's a cli, try using
python -m trace ...
:docs.python.org/2/library/trace.html– teng
Nov 24 '18 at 2:18