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

StationServer.stop() race conditions #974

Open
lalten opened this issue Dec 7, 2020 · 0 comments
Open

StationServer.stop() race conditions #974

lalten opened this issue Dec 7, 2020 · 0 comments

Comments

@lalten
Copy link
Contributor

lalten commented Dec 7, 2020

Repeatedly starting and stopping StationServer (e.g. in unit tests) reveals some race conditions in OpenHTF and Tornado.

  1. In openhtf/output/servers/web_gui_server.py:160: AttributeError: 'StationServer' object has no attribute 'server'
    This happens if you call stop() on the server before the run() thread has finished setting up the server

  2. In tornado/tcpserver.py:260: KeyError: 11
    I'm not sure why you'd hit this, but it also happens sometimes when you call StationServer's stop() method.

One workaround is to wrap it in a new context manager like

import contextlib
import time
import typing
import openhtf.output.servers.station_server

@contextlib.contextmanager
def safe_station_server() -> typing.Generator[openhtf.output.servers.station_server.StationServer, None, None]:
    """Workaround for race conditions in StationServer and Tornado libraries."""
    server = openhtf.output.servers.station_server.StationServer()
    server.start()
    while not hasattr(server, "server"):
        time.sleep(0)
    yield server
    try:
        server.stop()
    except KeyError:
        pass
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

No branches or pull requests

1 participant