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: ...@@ -143,8 +143,12 @@ def asyncio_run(coroutine: Coroutine) -> Any:
if sys.version_info >= (3, 7): if sys.version_info >= (3, 7):
return asyncio.run(coroutine) return asyncio.run(coroutine)
else: else:
loop = asyncio.get_event_loop() loop = asyncio.new_event_loop()
return loop.run_until_complete(coroutine) asyncio.set_event_loop(loop)
result = loop.run_until_complete(coroutine)
asyncio.set_event_loop(None)
loop.close()
return result
def GMT_timestamp() -> str: def GMT_timestamp() -> str:
...@@ -391,16 +395,18 @@ class Server: ...@@ -391,16 +395,18 @@ class Server:
self.stop_response = "DHParser server at {}:{} stopped!".format(host, port) self.stop_response = "DHParser server at {}:{} stopped!".format(host, port)
self.host.value = host.encode() self.host.value = host.encode()
self.port.value = port 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( self.server = cast(
asyncio.base_events.Server, asyncio.base_events.Server,
self.loop.run_until_complete( 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: try:
self.stage.value = SERVER_ONLINE self.stage.value = SERVER_ONLINE
self.server_messages.put(SERVER_ONLINE) self.server_messages.put(SERVER_ONLINE)
self.loop.run_forever() self.loop.run_forever()
finally: finally:
asyncio.set_event_loop(None)
self.server.close() self.server.close()
asyncio_run(self.server.wait_closed()) asyncio_run(self.server.wait_closed())
...@@ -442,7 +448,8 @@ class Server: ...@@ -442,7 +448,8 @@ class Server:
""" """
if self.server_process: if self.server_process:
assert not self.server_process.is_alive() 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.server_process = None
self._empty_message_queue() self._empty_message_queue()
self.server_process = Process( self.server_process = Process(
......
...@@ -401,7 +401,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -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(): for test_name, test_code in tests.get('match', dict()).items():
if not get_config_value('test_parallelization'): if not get_config_value('test_parallelization'):
print(' ' + test_name) print(' ' + str(test_name))
errflag = len(errata) errflag = len(errata)
try: try:
......
...@@ -68,7 +68,7 @@ Match test "entry" for parser "entry" failed: ...@@ -68,7 +68,7 @@ Match test "entry" for parser "entry" failed:
organization = {Wikipedia} 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. 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! 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; "%" 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 ...@@ -6,7 +6,6 @@ import concurrent.futures
import doctest import doctest
import multiprocessing import multiprocessing
import os import os
import platform
import sys import sys
import time import time
import threading import threading
...@@ -35,7 +34,7 @@ def run_doctests(module): ...@@ -35,7 +34,7 @@ def run_doctests(module):
if __name__ == "__main__": 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: if os.system('pypy3 -V') == 0:
interpreters.append('pypy3 ') interpreters.append('pypy3 ')
elif os.system('pypy -V') == 0: elif os.system('pypy -V') == 0:
...@@ -58,22 +57,23 @@ if __name__ == "__main__": ...@@ -58,22 +57,23 @@ if __name__ == "__main__":
"__init__.py"): "__init__.py"):
results.append(pool.submit(run_doctests, filename[:-3])) 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) 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 elapsed = time.time() - timestamp
print('\n Test-Duration: %.2f seconds' % elapsed) 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