-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Xiaodong Li <[email protected]>
- Loading branch information
1 parent
406befb
commit 25161a3
Showing
3 changed files
with
71 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: 'Localhost Echo Server' | ||
description: 'Starts an echo server using Python.' | ||
|
||
inputs: | ||
port_number: | ||
description: "Port for echo server." | ||
required: True | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Run localhost Echo server | ||
run: | | ||
python3 --version | ||
python3 $GITHUB_ACTION_PATH/local_echo_server.py --port_number=${{ inputs.port_number }} & | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import asyncio | ||
import logging | ||
import os | ||
from argparse import ArgumentParser | ||
|
||
logger = logging.getLogger('echoserver') | ||
|
||
async def echo_handler(reader, writer): | ||
address = writer.get_extra_info('peername') | ||
logger.debug('accept: %s', address) | ||
message = await reader.readline() | ||
writer.write(message) | ||
await writer.drain() | ||
writer.close() | ||
|
||
if __name__ == '__main__': | ||
parser = ArgumentParser(description='Localhost Echo server.') | ||
parser.add_argument('--port_number', | ||
type=int, | ||
required=True, | ||
help='Port for echo server.') | ||
args = parser.parse_args() | ||
logging.basicConfig() | ||
logger.setLevel(logging.DEBUG) | ||
loop = asyncio.get_event_loop() | ||
factory = asyncio.start_server( | ||
echo_handler, | ||
os.environ.get('HOST'), | ||
os.environ.get('PORT', args.port_number) | ||
) | ||
server = loop.run_until_complete(factory) | ||
try: | ||
loop.run_forever() | ||
except KeyboardInterrupt: | ||
pass | ||
server.close() | ||
loop.run_until_complete(server.wait_closed()) | ||
loop.close() |