OnionIoT / tau-lidar-server

Python package for Tau Lidar Camera application
MIT License
27 stars 7 forks source link

Webserver port not released properly if camera doesn't get initialized #22

Open greenbreakfast opened 3 years ago

greenbreakfast commented 3 years ago

Python and Library versions

Run python -V in the command-line and paste the output. Include some details on your system as well

Python 3.8.3

Run pip list | grep TauLidar in the command-line and paste the output. Include some details on your system as well

TauLidarCommon 0.0.1
TauLidarCamera 0.0.1
TauLidarServer 0.0.2

Camera Info

If possible, paste the output of camera.info() from Python (after camera has been successfully opened)

    model:      4.0
    firmware:   3.3
    uid:        69.549
    resolution: 160x60

Describe the bug

If the camera does not properly get initialized, the webserver port will not get properly released. The next time the TauLidarServer program is run, there will be a OSError: [Errno 48] Address already in use error.

The user must run the program with an argument to set a new port.

Steps to Reproduce

Data error, actual size: 36156, expected size: 38480
Bad frame ignored, bytes length: 36076
skip frame
Bad frame ignored, bytes length: 0
skip frame
Bad frame ignored, bytes length: 0
skip frame
Looking for connected Tau LiDAR Camera hardware ...
      DATA ERROR - length is 0

ToF camera opened successfully:
    model:      4.0
    firmware:   3.3
    uid:        69.549
    resolution: 160x60
    port:       /dev/cu.usbmodem00000000001A1
    IP address: 127.0.0.1
    URL:  http://127.0.0.1:8080

Press Ctrl + C keys to shutdown ...
Traceback (most recent call last):
  File "/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/lazar/workspace/onion/tau/tau-lidar-server/TauLidarServer/__main__.py", line 30, in <module>
    main()
  File "/Users/lazar/workspace/onion/tau/tau-lidar-server/TauLidarServer/__main__.py", line 27, in main
    server.serverLoop()
  File "/Users/lazar/workspace/onion/tau/tau-lidar-server/TauLidarServer/server.py", line 164, in serverLoop
    httpd = socketserver.TCPServer(("", HTTP_PORT), Handler)
  File "/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use
^CException ignored in: <module 'threading' from '/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/Users/lazar/.pyenv/versions/3.8.3/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt:

What is expected?

If the camera fails to initialize properly and the user exits the program with ctrl+c, the program should release the webserver port before shutting down.

What is actually happening?

The program closes and does not release the port. The user must specify a new port if they want to use the program.