Error opening a COM port using runserver

Hi

I’m trying to create a simple django app that will open a com port and read information, then display it on a webpage.

The problem I’m encountering is this

raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))

serial.serialutil.SerialException: could not open port ‘COM4’: PermissionError(13, ‘Access is denied.’, None, 5)

I’m using VScode and if I try running this code in debug mode I see that there is no problem opening the port, however I cannot get it to open when I type in “py manage.py runserver”

I’ve tried it through powershell in administration mode, I’ve tried opening VScode in admin mode and nothing changed
I’m positive the com port isn’t being used by anything else, also since I can run a simple py script to open the port no problem.

Any ideas where to start ?

That’s going to be really tough to do in a deployment style environment unless you know that you can appropriately share that com port across multiple threads in multiple processes.

What I would actually recommend is that you create a process external to Django to handle the com port and use something like redis or memcached or your database to exchange information from that process with your Django environment.

(This is similar in nature to other situations discussed here talking about collecting data from a Raspberry Pi GPIO interface. You might want to search for those discussions to get some more detailed ideas.)

Thanks a lot for the input, redis worked like a charm !!