Updating & Upgrading Pylint
Index
Updated docs
Some of the instructions were very brief and more explanations have been added to solve some of the most common problems. There is still work to be done here, but some things are still beyond my knowledge at the moment.
issue #2655
The console do not works properly because it always return an incorrect line error. It looks simple, but this bug is complex.
Arised Problems
The error is caused by entering 4 header lines when correcting the file, so there is always an error margin of 4 lines.
- 1 Creating a mini radi with RoboticsApplicationManager custom branch.
- 2 Creating a mini radi with the corrections made.
After several tests, I have found that for some reason the margin of error is sometimes 6 lines instead of 4.
I have also reopened an issue that occurred when quickly relaunching docker, which generates an error because port 5900 0 5901 is not cleared.
To solve the error I have found two temporal solutions, the first is to remove the docker that has not been closed properly, this closes the port forcibly:
1
docker ps -a
1
docker rm [docker_id]
Another option is to relaunch it but with other options, that is to say, alternate between launching it with and without graphic acceleration, I suppose that in this case another port is opened and gives the previous one time to close.
1
sh scripts/develop_academy.sh -g
To find a solution we are checking what is keeping the ports busy, using commands such as:
1
lsof -i :5901
1
sudo netstat -anp | find :5901
The connection timeout in this line of vnc_server.py
has also been increased.
1
def wait_for_port(self, host, port, timeout=60):
But it’s still not working.
Other way to solve this issue, is killing the process from inside the docker with this command:
1
fuser -k 5901/tcp
Solving the original issue
The process is being much slower than expected, because of all the problems that are arising, I am also not able to find the point where the errors are returned, as they are not always printed by the docker console, usually the errors are printed in the terminal where you launch the docker. If you add to this that there is not always a 4 line error, and for each test you have to relaunch the docker…
After a lot of debugging work, I realised that the import errors originate inside the manager.py. The problem is that the manager creates a subprocess to launch the program, which truncates the standard and error outputs to appear on the console, the problem here is that we should take that output before appearing on the console and modify it.
Code to modify line error:
1
2
3
4
5
6
7
8
9
10
def adjust_line_numbers(error_output):
pattern = re.compile(r'line (\d+)')
adjusted_output = error_output
for match in pattern.finditer(error_output):
line_number = int(match.group(1))
adjusted_line_number = max(line_number - 6, 1)
adjusted_output = adjusted_output.replace(f'line {line_number}', f'line {adjusted_line_number}', 1)
return adjusted_output
The solution I was trying was to redirect that output to modify it by hand and put the corresponding line number, what is the problem? if it is an error outside the loop the error is 4 lines and inside or below the loop the error is 6 lines, this is due to how the lines are added to control the iteration frequency def add_frequency_control(self, code):
. After trying several things, using conditions to identify the different errors, I realised that it is very complicated to redirect that output without leaving open pipes and even knowing if the error was inside or outside the loop.
For these reasons, I tried to modify the way in which these extra lines are added, the import lines (4) were added inside the frontend and in the exercise I was testing loc_vaccumm cleaner
, so that now the initial code had two extra lines. Now the error was only 2 lines inside or below the loop. To eliminate this error, I thought about removing that line and adding it to the loop, the problem is that there are no assignment statements like this in python loops. For this reason the only viable solution I can find is to either add all these lines to the initial program or leave the 1 line error inside or below the loop.
I found all the programs I needed to modify using:
1
grep -r "# Enter sequential code!" [RoboticsAcademy path]
The code:
1
2
3
4
5
6
7
8
import GUI
import HAL
import time
from datetime import datetime
# Enter sequential code!
while True:
# Enter iterative code!
Real issue found
After more debugging, I realised that the manager, before executing the user’s code, checks that it is ok using pylint, the problem is, that it was using an obsolete module of this library. In addition, there were no traces to check for these errors, so there was never any indication of an error.
Now that this has been clarified, the two programs that use this module have been updated.
At this point, it remains to properly notify the user of errors, but there is no longer an error in the line number.
New Functionalities
To get the missing functionality of notifying with an error pop-up when errors have been detected in the code, apart from a great understanding of how the manager works we also have to learn how the coms_manager works. This is quite complicated, so I decided to start trying to send errors through the browser console so that the user can debug the program without problems.
At this point, I thought it was as simple as saving the program which runs pylint inside the docker and launching it, this for some reason doesn’t work, neither does redirecting the outputs, as they always end up redirected to the developer terminal. After many tests of redirections and different ways of launching it, I decided to give it another approach. I was looking from where the terminal was launched, which was not entirely clear to me, as the supposed launcher in charge of it doesn’t seem to be used. After several tests, I tried to create a function inside the console class to launch commands in it. To do so, I initialised the class in the manager and tried to launch commands there (without success). For this I had to create a new image adding the xdotool
module in the docker dependencies.
Here is an aproximation of the new function:
1
2
3
4
5
6
def send_command_to_xterm(self, command):
find_xterm_cmd = "xdotool search --name xterm"
window_id = subprocess.check_output(find_xterm_cmd, shell=True).strip()
send_cmd = f"xdotool type --window {window_id} '{command}' && xdotool key --window {window_id} Return"
subprocess.call(send_cmd, shell=True)
This was not working.
Closing issue
Thanks to a collaborator, we have been able to redirect the output from the developer console to the user console. This way:
1
2
with open('/dev/pts/1', 'w') as console:
console.write(errors + "\n\n")
issue #2576
As I explained above, for some reason a port is not closed properly, which prevents communication between the docker and the browser on relaunch.
issue #147
In the meantime, I discovered that several threads were being launched unnecessarily, which slowed down the execution of the manager, but after removing them, a performance improvement is noticeable.
Closing issue
Using this:
1
self.ros_version = subprocess.check_output(["bash", "-c", "echo $ROS_DISTRO"])
We do not need to launch de same command several times.