WARNING - Python WaitCommandComplete timed out

  • zz912
  • Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
2 years 7 months ago - 2 years 7 months ago #296649 by zz912
Hello,

Few people know that the command self.command.wait_complete() has a time limit that can be set and the default value is 5seconds.
Code:
            self.command.wait_complete()             self.command.mode(linuxcnc.MODE_MDI)             self.command.wait_complete()             self.command.mdi("G91 G1 X10 F200")             self.command.wait_complete(2)             self.command.mdi("G91 G1 Y10 F200")             self.command.wait_complete()                        self.command.mode(linuxcnc.MODE_MANUAL)             self.command.wait_complete()

The problem is that if this limit is exceeded, the source code continues and there is no warning.
I was able to create two kinds of warnings.

1) silent warning with fprintf. If the time limit is exceeded, the source code continues, but at least an error note appears in the terminal.
 
2) drastically stop the code with PyErr_Format
 
I would like to make a Pull Request, but I don't know which option to choose. Can any of you think of another option?

github.com/LinuxCNC/linuxcnc/blob/master...ns/emcmodule.cc#L213
Code:
static int emcWaitCommandComplete(pyCommandChannel *s, double timeout) {     double start = etime();     do {         double now = etime();         if(s->s->peek() == EMC_STAT_TYPE) {            EMC_STAT *stat = (EMC_STAT*)s->s->get_address();            int serial_diff = stat->echo_serial_number - s->serial;            if (serial_diff > 0) {                 return RCS_DONE;            }            if (serial_diff == 0 &&                ( stat->status == RCS_DONE || stat->status == RCS_ERROR )) {                 return stat->status;            }         }         esleep(fmin(timeout - (now - start), EMC_COMMAND_DELAY));     } while (etime() - start < timeout);     PyErr_Format( error, "Python WaitCommandComplete timed out");     //fprintf(stderr,"Error - Python WaitCommandComplete timed out \n");     return -1; [attachment=60361]fprintf.png[/attachment]
Last edit: 2 years 7 months ago by zz912.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #296683 by cmorley
Why don't you check for the error in the python code?
Code:
result = self.command.wait_complete(timeout) if result == -1:        print( 'Command timed out: ({} second)'.format(timeout))
Last edit: 2 years 7 months ago by cmorley.

Please Log in or Create an account to join the conversation.

  • zz912
  • Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
2 years 7 months ago #296703 by zz912

Why don't you check for the error in the python code?

Code:
result = self.command.wait_complete(timeout) if result == -1:        print( 'Command timed out: ({} second)'.format(timeout))
When you know that a time out problem will occur, you can solve it like this. However, a situation happened to me when the program was behaving randomly. It was only after much searching that I found out that WaitCommandComplete has a timeout. I'll be on the lookout for it forever. I would like other developers to be aware of this while debugging their programs. I think it can be very dangerous for moving (eg self.command.mdi("G91 G1 Y10 F200") ). Movements up to 5s are fine. For movements above 5s, the developer will notice that something is weird. Moves lasting 5s will behave randomly.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #296715 by JT
I don't use command.wait_complete() on MDI commands because it stops the program at that point until the command completes. No status will update in your GUI because it acts like a time.sleep() and stops processing.

JT

Please Log in or Create an account to join the conversation.

Time to create page: 0.050 seconds
Powered by Kunena Forum