Change event loop on windows (#4075)
* Change event loop on windows * fix * split PR * remove set event loop * Add paulus suggestion * fix missing import * revert stuff from PR Splitting * fix event loop on test
This commit is contained in:
parent
e4a713207d
commit
26490109ac
4 changed files with 18 additions and 3 deletions
|
@ -14,6 +14,7 @@ from homeassistant.const import (
|
||||||
__version__,
|
__version__,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
REQUIRED_PYTHON_VER,
|
REQUIRED_PYTHON_VER,
|
||||||
|
REQUIRED_PYTHON_VER_WIN,
|
||||||
RESTART_EXIT_CODE,
|
RESTART_EXIT_CODE,
|
||||||
)
|
)
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
from homeassistant.util.async import run_callback_threadsafe
|
||||||
|
@ -64,7 +65,12 @@ def monkey_patch_asyncio():
|
||||||
|
|
||||||
def validate_python() -> None:
|
def validate_python() -> None:
|
||||||
"""Validate we're running the right Python version."""
|
"""Validate we're running the right Python version."""
|
||||||
if sys.version_info[:3] < REQUIRED_PYTHON_VER:
|
if sys.platform == "win32" and \
|
||||||
|
sys.version_info[:3] < REQUIRED_PYTHON_VER_WIN:
|
||||||
|
print("Home Assistant requires at least Python {}.{}.{}".format(
|
||||||
|
*REQUIRED_PYTHON_VER_WIN))
|
||||||
|
sys.exit(1)
|
||||||
|
elif sys.version_info[:3] < REQUIRED_PYTHON_VER:
|
||||||
print("Home Assistant requires at least Python {}.{}.{}".format(
|
print("Home Assistant requires at least Python {}.{}.{}".format(
|
||||||
*REQUIRED_PYTHON_VER))
|
*REQUIRED_PYTHON_VER))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -6,6 +6,7 @@ PATCH_VERSION = '0.dev0'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 4, 2)
|
REQUIRED_PYTHON_VER = (3, 4, 2)
|
||||||
|
REQUIRED_PYTHON_VER_WIN = (3, 5, 2)
|
||||||
|
|
||||||
PROJECT_NAME = 'Home Assistant'
|
PROJECT_NAME = 'Home Assistant'
|
||||||
PROJECT_PACKAGE_NAME = 'homeassistant'
|
PROJECT_PACKAGE_NAME = 'homeassistant'
|
||||||
|
|
|
@ -107,7 +107,11 @@ class HomeAssistant(object):
|
||||||
|
|
||||||
def __init__(self, loop=None):
|
def __init__(self, loop=None):
|
||||||
"""Initialize new Home Assistant object."""
|
"""Initialize new Home Assistant object."""
|
||||||
self.loop = loop or asyncio.get_event_loop()
|
if sys.platform == "win32":
|
||||||
|
self.loop = loop or asyncio.ProactorEventLoop()
|
||||||
|
else:
|
||||||
|
self.loop = loop or asyncio.get_event_loop()
|
||||||
|
|
||||||
self.executor = ThreadPoolExecutor(max_workers=5)
|
self.executor = ThreadPoolExecutor(max_workers=5)
|
||||||
self.loop.set_default_executor(self.executor)
|
self.loop.set_default_executor(self.executor)
|
||||||
self.loop.set_exception_handler(self._async_exception_handler)
|
self.loop.set_exception_handler(self._async_exception_handler)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""Test the helper method for writing tests."""
|
"""Test the helper method for writing tests."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
@ -33,7 +34,10 @@ def get_test_config_dir(*add_path):
|
||||||
|
|
||||||
def get_test_home_assistant():
|
def get_test_home_assistant():
|
||||||
"""Return a Home Assistant object pointing at test config dir."""
|
"""Return a Home Assistant object pointing at test config dir."""
|
||||||
loop = asyncio.new_event_loop()
|
if sys.platform == "win32":
|
||||||
|
loop = asyncio.ProactorEventLoop()
|
||||||
|
else:
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
|
||||||
hass = loop.run_until_complete(async_test_home_assistant(loop))
|
hass = loop.run_until_complete(async_test_home_assistant(loop))
|
||||||
hass.allow_pool = True
|
hass.allow_pool = True
|
||||||
|
|
Loading…
Add table
Reference in a new issue