Closed dauheeIRL closed 1 year ago
Sorry about that. I didn't mean to break anything. Already doing a research how to fix it.
@dauheeIRL are you able to test this branch to confirm that it is OK now on Windows.
The tests are passing on Windows 11 with Python 3.11, but I don't have access to a datalogger from that machine to confirm personally.
Oh wow that was quick. What I've done is a loop to try every 20 seconds and it seems to generate an error periodically:
Exception in thread Thread-36 (_data_receiver):
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Program Files\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python310\lib\site-packages\pysolarmanv5\pysolarmanv5.py", line 298, in _data_receiver
data = self.sock.recv(1024)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
it also leaves a buildup of threads (QueueFeederThread + Process_Request_Thread), some of them seem to clear but others don't. when I call modbus.disconnect() after getting my logger data I get the following error:
Exception in thread Thread-41 (_data_receiver):
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Program Files\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python310\lib\site-packages\pysolarmanv5\pysolarmanv5.py", line 298, in _data_receiver
data = self.sock.recv(1024)
OSError: [WinError 10038] An operation was attempted on something that is not a socket
I will have time tomorrow to do some extra testing
Was able to reproduce this. If the exit event is set early, however, as in 638ed8e, the socket is closed properly on disconnect. Can you confirm this .
Thats working perfectly!! I hammered it every second with a load of reads and did lots of connecting and disconnecting and couldn't get it to complain :)
Nice one, much appreciated
Thank you for the cooperation! By the way you can use the auto_reconnect=True option and to read/write indefinitely. There is no need to disconnect and create new instances all the time.
Thats great thanks. Yeah auto_reconnect=True has been working flawlessly
Actually after time I still get error after time with auto_reconnect=True:
pysolarmanv5.pysolarmanv5.NoSocketAvailableError: Connection already closed.
I can proceed by catching this and just recreating modbus. I tried to see if anything in modbus.sock could be checked beforehand but nothing that I could see. I could raise another issue if you like for this
This is an indication for network connectivity issues. The _reconnect function cannot open connection to the data logger when the previous connection is closed. In verbose mode this is logged with No socket available! Reconnect failed.
Resolved by #38.
Thanks @dauheeIRL for the report, and @githubDante for the fix!
I get the following error from windows 10 22H2, python 3.10.2, when _socket_setup is called in pysolarmanv5.py:
AttributeError: module 'select' has no attribute 'poll'
select.poll() is not supported on windows and since the commit below, compatibility is broken:
https://github.com/jmccrohan/pysolarmanv5/commit/bba4543bbaa469d54f43b76d2f8ef8d7d5889dff
Just wondering if you are interested in keeping compatible with windows and I could see if there is a workaround (with my crude abilities), or maybe you would be better suited.