Commit 098b35d6 authored by oroulet's avatar oroulet Committed by oroulet

directly start and stop thread_loop

parent 90ef44bf
......@@ -8,7 +8,7 @@ install:
- pip install lxml
- pip install aiofiles
- pip install asyncio-contextmanager
- pip install pytest
- pip install pytest --upgrade
- pip install pytest-asyncio
- pip install cryptography
# command to run tests
......
......@@ -48,14 +48,28 @@ _ref_count = 0
_tloop = None
def start_thread_loop():
print("START")
global _tloop
_tloop = ThreadLoop()
_tloop.start()
return _tloop
def stop_thread_loop():
print("STOP")
global _tloop
_tloop.stop()
_tloop.join()
def get_thread_loop():
global _tloop
if _tloop is None:
_tloop = ThreadLoop()
_tloop.start()
start_thread_loop()
global _ref_count
_ref_count += 1
print("RETURNING", _tloop, _ref_count)
return _tloop
......@@ -66,9 +80,7 @@ def release_thread_loop():
global _ref_count
if _ref_count == 0:
_ref_count -= 1
print("STOPPING", _tloop, _ref_count)
_tloop.stop()
_tloop.join()
stop_thread_loop()
def _get_super(func):
......@@ -90,7 +102,8 @@ def syncmethod(func):
sup = _get_super(func)
super_func = getattr(sup, name)
global _tloop
return _tloop.post(super_func(self, *args, **kwargs))
result = _tloop.post(super_func(self, *args, **kwargs))
return result
return wrapper
......@@ -101,7 +114,6 @@ class Client(client.Client):
@syncmethod
def connect(self):
print("NOT HEERE")
pass
@syncmethod
......
......@@ -2,7 +2,7 @@ import time
import pytest
from opcua.sync import Client
from opcua.sync import Client, start_thread_loop, stop_thread_loop
@pytest.fixture
......@@ -11,7 +11,14 @@ def server():
@pytest.fixture
def client():
def tloop():
t_loop = start_thread_loop()
yield t_loop
stop_thread_loop()
@pytest.fixture
def client(tloop):
c = Client("opc.tcp://localhost:4840/freeopcua/server")
c.connect()
yield c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment