Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
261b1758
Commit
261b1758
authored
Mar 06, 2019
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- sync commit
parent
3d55f49e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
DHParser/server.py
DHParser/server.py
+18
-0
test/test_server.py
test/test_server.py
+2
-0
No files found.
DHParser/server.py
View file @
261b1758
...
...
@@ -35,6 +35,7 @@ of module `server`, i.e. the compilation-modules, to decide.
import
asyncio
from
multiprocessing
import
Value
,
Queue
from
typing
import
Callable
,
Any
from
DHParser.preprocess
import
BEGIN_TOKEN
,
END_TOKEN
,
TOKEN_DELIMITER
...
...
@@ -47,10 +48,18 @@ SERVER_ERROR = "COMPILER-SERVER-ERROR"
CompileFunc
=
Callable
[[
str
,
str
],
Any
]
# compiler_src(source: str, log_dir: str) -> Any
SERVER_OFFLINE
=
0
SERVER_STARTING
=
1
SERVER_ONLINE
=
2
class
CompilerServer
:
def
__init__
(
self
,
compiler
:
CompileFunc
):
self
.
compiler
=
compiler
self
.
max_source_size
=
get_config_value
(
'max_source_size'
)
self
.
stage
=
Value
(
'b'
,
SERVER_OFFLINE
)
self
.
server_messages
=
Queue
()
async
def
handle_compilation_request
(
self
,
reader
:
asyncio
.
StreamReader
,
...
...
@@ -68,7 +77,16 @@ class CompilerServer:
async
def
serve
(
self
,
address
:
str
=
'127.0.0.1'
,
port
:
int
=
8888
):
server
=
await
asyncio
.
start_server
(
self
.
handle_compilation_request
,
address
,
port
)
async
with
server
:
self
.
stage
.
value
=
SERVER_ONLINE
self
.
server_messages
.
put
(
SERVER_ONLINE
)
await
server
.
serve_forever
()
def
run_server
(
self
,
address
:
str
=
'127.0.0.1'
,
port
:
int
=
8888
):
self
.
stage
.
value
=
SERVER_STARTING
asyncio
.
run
(
self
.
serve
(
address
,
port
))
def
wait_until_server_online
(
self
):
if
self
.
server_messages
.
get
()
!=
SERVER_ONLINE
:
raise
AssertionError
(
'could not start server!?'
)
assert
self
.
stage
.
value
==
SERVER_ONLINE
test/test_server.py
View file @
261b1758
...
...
@@ -41,6 +41,8 @@ class TestServer:
cs
=
CompilerServer
(
compiler_dummy
)
p
=
Process
(
target
=
cs
.
run_server
)
p
.
start
()
cs
.
wait_until_server_online
()
async
def
compile
(
src
,
log_dir
):
reader
,
writer
=
await
asyncio
.
open_connection
(
'127.0.0.1'
,
8888
)
writer
.
write
(
src
.
encode
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment