0

I'm writing a large project in python 3 and running it in an anaconda environment. Part of the project takes numpy arrays (2d coordinates) as input and requires that no 2 consecutive coordinates are the same. So I iterate every array removing duplicates before they arrive at that part.

I was testing my program and it started breaking at the part that requires no duplicate coordinates (division by 0 was occurring), so I started debugging to find out where the duplicate coordinates were and how they were getting through the duplicate checker.

I decided to check for duplicates JUST before code block that was giving a division by 0 error, and if a duplicate is encountered, print something and exit().

Strangely, when I ran the code, it never exited, it just processed through like normal with no errors. I was confused so I did some more debugging to see what the coords that were previously duplicates appeared to be now, and it turns out they are quite different.

There is no randomness in my code and as far as I'm aware there is no multithreading or anything unless anaconda does that automatically or something.

My project is too large to go into details but below is the part that checks for consecutive duplicate coordinates, if exit() is commented out and instead the print() and input() is kept in, I indeed get prompted for input as my program reaches here and finds duplicates. If I instead comment out print() and input() and keep exit() as it is below, the program does not exit here, as there are somehow no longer any duplicates that can trigger this condition.

for coordI in range(coordArray.shape[0]-1):
    if coordArray[coordI][0][0]==coordArray[coordI+1][0][0] and coordArray[coordI][0][1]==coordArray[coordI+1][0][1]:
        exit()

        # print('???')
        # input()

I know I haven't given every detail but I don't need to know the exact reason this is happening, I just need to know what could possibly cause this behaviour in python/anaconda

  • 2
    Guess: you have a plain `try..except:` somewhere that catches the `SystemExit` exception raised by `exit` and silently suppresses it. – deceze Apr 24 '22 at 06:55
  • You're a genius, it never occurred to me that exit raises an exception, now I know, this was the right answer but the question was closed – jgkilian777 Apr 24 '22 at 07:14

0 Answers0