'io.UnsupportedOperation: fileno even in PowerShell with Administration permissions

So I'm trying to read data from a serial port using asyncio. I have a function called start_receiver as below.

def start_receiver(ser, exit_queue, msg_queue):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.add_reader(ser.fileno(), receiver, ser, msg_queue)
    loop.run_until_complete(forever(exit_queue))
    loop.close()

and the receiver function

def receiver(file_descriptor, queue):
    # Reading 1 byte, followed by whatever is left in the
    # read buffer, as suggested by the developer of PySerial.
    buff = file_descriptor.read()
    buff = buff + file_descriptor.read(file_descriptor.inWaiting())
    while buff:
        while buff[0] != b'\x02':
            buff = buff[1:]
        x = buff[1:]
        buff = []
        queue.put_nowait(pickle.dumps((x, datetime.now()), protocol=5))

ser is called as ser = serial.Serial('COM3', 38400, timeout=0)

For some reason, I got the error

Traceback (most recent call last):
  File "\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "\PycharmProjects\serialReading\receiver.py", line 13, in start_receiver
    loop.add_reader(ser.fileno(), receiver, ser, msg_queue)
io.UnsupportedOperation: fileno

I've read this and I've tried to activate my virtual env and launch the script from the Windows Power Shell (I'm using Win10) as Administrator but I got the same error.

Is there a way to work around or fix the issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source