Commit 15901cf6 authored by eckhart's avatar eckhart

- server.py: eliminated reace condition in server module

parent 3e3cbffd
......@@ -143,8 +143,12 @@ def asyncio_run(coroutine: Coroutine) -> Any:
if sys.version_info >= (3, 7):
return asyncio.run(coroutine)
else:
loop = asyncio.get_event_loop()
return loop.run_until_complete(coroutine)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(coroutine)
asyncio.set_event_loop(None)
loop.close()
return result
def GMT_timestamp() -> str:
......@@ -391,16 +395,18 @@ class Server:
self.stop_response = "DHParser server at {}:{} stopped!".format(host, port)
self.host.value = host.encode()
self.port.value = port
self.loop = asyncio.get_event_loop()
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.server = cast(
asyncio.base_events.Server,
self.loop.run_until_complete(
asyncio.start_server(self.handle_request, host, port)))
asyncio.start_server(self.handle_request, host, port, loop=self.loop)))
try:
self.stage.value = SERVER_ONLINE
self.server_messages.put(SERVER_ONLINE)
self.loop.run_forever()
finally:
asyncio.set_event_loop(None)
self.server.close()
asyncio_run(self.server.wait_closed())
......@@ -442,7 +448,8 @@ class Server:
"""
if self.server_process:
assert not self.server_process.is_alive()
self.server_process.close()
if sys.version_info >= (3, 7):
self.server_process.close()
self.server_process = None
self._empty_message_queue()
self.server_process = Process(
......
......@@ -401,7 +401,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
for test_name, test_code in tests.get('match', dict()).items():
if not get_config_value('test_parallelization'):
print(' ' + test_name)
print(' ' + str(test_name))
errflag = len(errata)
try:
......
......@@ -68,7 +68,7 @@ Match test "entry" for parser "entry" failed:
organization = {Wikipedia}
}
6:68: Error (1010): '}' ~ expected, "%E2\%80\%9..." found!
6:68: Error (1010): '}' ~ expected, »%E2\%80\%9...« found!
6:69: Error (1040): Parser stopped before end! trying to recover but stopping history recording at this point.
7:1: Error (1020): Parser did not match!
Most advanced: 6, 68: entry->:ZeroOrMore->:Series->content->:Series->text->:Alternative->CONTENT_STRING->:Alternative->:Series->:Lookahead->/(?i)%/; MATCH; "%"
......
......@@ -6,7 +6,6 @@ import concurrent.futures
import doctest
import multiprocessing
import os
import platform
import sys
import time
import threading
......@@ -35,7 +34,7 @@ def run_doctests(module):
if __name__ == "__main__":
interpreters = [] # ['python3 ' if os.system('python3 -V') == 0 else 'python ']
interpreters = ['python3 ' if os.system('python3 -V') == 0 else 'python ']
if os.system('pypy3 -V') == 0:
interpreters.append('pypy3 ')
elif os.system('pypy -V') == 0:
......@@ -58,22 +57,23 @@ if __name__ == "__main__":
"__init__.py"):
results.append(pool.submit(run_doctests, filename[:-3]))
# unit tests
for interpreter in interpreters:
if os.system(interpreter + '--version') == 0:
# for filename in os.listdir('test'):
# if filename.startswith('test_'):
# command = interpreter + os.path.join('test', filename)
# results.append(pool.submit(run_unittests, command))
os.system(' '.join([interpreter, '-c',
'''"import sys; '''
'''sys.path.extend(['DHParser']);'''
'''import testing; testing.run_path('%s')"''' %
scriptdir.replace('\\', '\\\\'),
os.path.join(os.getcwd(), 'test')]))
concurrent.futures.wait(results)
# unit tests
for interpreter in interpreters:
if os.system(interpreter + '--version') == 0:
# for filename in os.listdir('test'):
# if filename.startswith('test_'):
# command = interpreter + os.path.join('test', filename)
# results.append(pool.submit(run_unittests, command))
os.system(' '.join([interpreter, '-c',
'''"import sys; '''
'''sys.path.extend(['DHParser']);'''
'''import testing; testing.run_path('%s')"''' %
scriptdir.replace('\\', '\\\\'),
os.path.join(os.getcwd(), 'test')]))
elapsed = time.time() - timestamp
print('\n Test-Duration: %.2f seconds' % elapsed)
......
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