Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify monitor websocket use #986

Merged
merged 11 commits into from
Mar 15, 2018

Conversation

jenshnielsen
Copy link
Collaborator

Should make it compatible with the latest release of websockets python package and fixes issues with restarting the monitor

@Dominik-Vogel

@jenshnielsen jenshnielsen changed the title simplifty monitor websocket use [WIP] simplifty monitor websocket use Mar 1, 2018
@codecov
Copy link

codecov bot commented Mar 1, 2018

Codecov Report

Merging #986 into master will decrease coverage by 0.12%.
The diff coverage is 10%.

@@           Coverage Diff            @@
##           master   #986      +/-   ##
========================================
- Coverage   79.12%    79%   -0.13%     
========================================
  Files          45     45              
  Lines        6425   6431       +6     
========================================
- Hits         5084   5081       -3     
- Misses       1341   1350       +9

@jenshnielsen
Copy link
Collaborator Author

Only remaining issue is an annoying warning when reloading the monitor webpage. This seems to only happen with version 4.0.1 (and 4.0.0?) when reloading from Firefox (at least it doesn't seem to happen when reloading from chrome.

As seen below the connection is correctly closed but then a new one is created that fails immediately with a loud warning. This is subsequently replaced by a new one again that works as expected.

2018-03-02 15:42:54,688 - qcodes.monitor.monitor - DEBUG - sending.. to <websockets.server.WebSocketServerProtocol object at 0x117c965c0>
2018-03-02 15:42:54,700 - websockets.protocol - DEBUG - server > Frame(fin=True, opcode=1, data=b'{"ts": 1520001774.68816, "parameters": [{"instrument": "<DummyInstrument: dac>", "parameters": [{"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch1", "unit": "V"}, {"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch2", "unit": "V"}]}]}', rsv1=False, rsv2=False, rsv3=False)
2018-03-02 15:42:54,706 - qcodes.monitor.monitor - DEBUG - sending.. to <websockets.server.WebSocketServerProtocol object at 0x117c973c8>
2018-03-02 15:42:54,710 - websockets.protocol - DEBUG - server > Frame(fin=True, opcode=1, data=b'{"ts": 1520001774.704313, "parameters": [{"instrument": "<DummyInstrument: dac>", "parameters": [{"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch1", "unit": "V"}, {"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch2", "unit": "V"}]}]}', rsv1=False, rsv2=False, rsv3=False)
2018-03-02 15:42:58,147 - websockets.protocol - DEBUG - server < Frame(fin=True, opcode=8, data=b'\x03\xe9', rsv1=False, rsv2=False, rsv3=False)
2018-03-02 15:42:58,151 - websockets.protocol - DEBUG - server > Frame(fin=True, opcode=8, data=b'\x03\xe9', rsv1=False, rsv2=False, rsv3=False)
2018-03-02 15:42:58,153 - websockets.protocol - DEBUG - server x half-closing TCP connection
2018-03-02 15:42:58,157 - websockets.protocol - DEBUG - server - eof_received()
2018-03-02 15:42:58,158 - websockets.protocol - DEBUG - server - connection_lost(None)
2018-03-02 15:42:58,162 - websockets.protocol - DEBUG - server x closing TCP connection
2018-03-02 15:42:58,230 - websockets.protocol - DEBUG - server - connection_made(<_SelectorSocketTransport fd=89 read=idle write=<idle, bufsize=0>>)
2018-03-02 15:42:58,233 - qcodes.monitor.monitor - DEBUG - sending.. to <websockets.server.WebSocketServerProtocol object at 0x117c22588>
2018-03-02 15:42:58,243 - websockets.protocol - DEBUG - server > Frame(fin=True, opcode=1, data=b'{"ts": 1520001778.2337291, "parameters": [{"instrument": "<DummyInstrument: dac>", "parameters": [{"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch1", "unit": "V"}, {"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch2", "unit": "V"}]}]}', rsv1=False, rsv2=False, rsv3=False)
2018-03-02 15:42:58,291 - websockets.protocol - DEBUG - server - connection_lost([Errno 54] Connection reset by peer)
2018-03-02 15:42:58,292 - websockets.protocol - WARNING - Error in data transfer
Traceback (most recent call last):
  File "/Users/jhn/.pyenv/versions/3.6.4/envs/qcodes-3.6.4/lib/python3.6/site-packages/websockets/protocol.py", line 496, in transfer_data
    msg = yield from self.read_message()
  File "/Users/jhn/.pyenv/versions/3.6.4/envs/qcodes-3.6.4/lib/python3.6/site-packages/websockets/protocol.py", line 526, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/Users/jhn/.pyenv/versions/3.6.4/envs/qcodes-3.6.4/lib/python3.6/site-packages/websockets/protocol.py", line 591, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/Users/jhn/.pyenv/versions/3.6.4/envs/qcodes-3.6.4/lib/python3.6/site-packages/websockets/protocol.py", line 632, in read_frame
    extensions=self.extensions,
  File "/Users/jhn/.pyenv/versions/3.6.4/envs/qcodes-3.6.4/lib/python3.6/site-packages/websockets/framing.py", line 100, in read
    data = yield from reader(2)
  File "/Users/jhn/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/asyncio/streams.py", line 674, in readexactly
    yield from self._wait_for_data('readexactly')
  File "/Users/jhn/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
    yield from self._waiter
  File "/Users/jhn/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 723, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 54] Connection reset by peer
2018-03-02 15:42:58,302 - websockets.protocol - DEBUG - server ! failing WebSocket connection: 1011 
2018-03-02 15:42:58,305 - websockets.protocol - DEBUG - server x half-closing TCP connection
2018-03-02 15:42:58,312 - websockets.protocol - DEBUG - server x closing TCP connection
2018-03-02 15:42:58,517 - websockets.protocol - DEBUG - server - connection_made(<_SelectorSocketTransport fd=89 read=idle write=<idle, bufsize=0>>)
2018-03-02 15:42:58,523 - qcodes.monitor.monitor - DEBUG - sending.. to <websockets.server.WebSocketServerProtocol object at 0x117c18748>
2018-03-02 15:42:58,525 - websockets.protocol - DEBUG - server > Frame(fin=True, opcode=1, data=b'{"ts": 1520001778.522599, "parameters": [{"instrument": "<DummyInstrument: dac>", "parameters": [{"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch1", "unit": "V"}, {"value": "0", "ts": 1520001763.0, "raw_value": 0, "name": "Gate ch2", "unit": "V"}]}]}', rsv1=False, rsv2=False, rsv3=False)

@Dominik-Vogel
Copy link
Contributor

I have been testing in context with the StationConfigurator it and it works excellently.

@Dominik-Vogel
Copy link
Contributor

There is still some problems:
When I do this in ipython:

from qcodes.monitor.monitor import Monitor
Monitor()
exit()

IPython crashes.
I tried implementing in the Monitor class without success:

    def __del__(self):
        if Monitor.running:
            Monitor.running.stop()

The following does not crash

from qcodes.monitor.monitor import Monitor
Monitor()
Monitor.running.stop()
exit()

jenshnielsen and others added 4 commits March 8, 2018 10:36
This ensures that the server is always stopped before the real join is called avoiding a deadlock on a running ws server
@jenshnielsen
Copy link
Collaborator Author

So it looks like join is called on the thread before either an atexit or a __del__ method has the chance to stop the server. Fixed this by overwriting join to close the server

Copy link
Contributor

@jana-d jana-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed my issues.

@jenshnielsen jenshnielsen changed the title [WIP] simplifty monitor websocket use Simplifty monitor websocket use Mar 9, 2018
@jenshnielsen
Copy link
Collaborator Author

@Dominik-Vogel I think this is ready to go

@WilliamHPNielsen WilliamHPNielsen changed the title Simplifty monitor websocket use Simplify monitor websocket use Mar 9, 2018
So ensure it's awaited correctly. Also avoid calling is closed from outside the thread
@jenshnielsen
Copy link
Collaborator Author

@Dominik-Vogel I think the last issue is fixed now. wait_closed() is a co-routine that needs to be awaited.

@Dominik-Vogel Dominik-Vogel merged commit c82d223 into microsoft:master Mar 15, 2018
giulioungaretti pushed a commit that referenced this pull request Mar 15, 2018
Author: Jens Hedegaard Nielsen <jenshnielsen@gmail.com>

    Simplify monitor websocket use (#986)
@jenshnielsen jenshnielsen deleted the rewrite_monitor branch March 16, 2018 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants