announce server decorator complete
This commit is contained in:
parent
e55ae1167b
commit
63f31b636a
@ -16,25 +16,23 @@ def get_ip_address():
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
# Update these with the correct values for your host and server
|
# Update these with the correct values for your host and server
|
||||||
HOST_SERVER_IP = "192.168.1.113"
|
|
||||||
HOST_SERVER_PORT = 4999
|
|
||||||
|
|
||||||
SERVER_IP = get_ip_address()
|
|
||||||
SERVER_PORT = 8000
|
|
||||||
|
|
||||||
sio = socketio.AsyncClient()
|
sio = socketio.AsyncClient()
|
||||||
|
|
||||||
async def announce_server(**kwargs):
|
async def _announce_server(**kwargs):
|
||||||
|
HOST_SERVER_IP = "0.0.0.0"
|
||||||
|
HOST_SERVER_PORT = 4999
|
||||||
SERVER_NAME = "server_1"
|
SERVER_NAME = "server_1"
|
||||||
server_name = kwargs.get("name", SERVER_NAME)
|
SERVER_PORT = 8000
|
||||||
# SERVER_IP = kwargs.get("ip", SERVER_IP)
|
SERVER_NAME = kwargs.get("name", SERVER_NAME)
|
||||||
# SERVER_PORT = kwargs.get("port", SERVER_PORT)
|
SERVER_IP = kwargs.get("ip", get_ip_address())
|
||||||
# HOST_SERVER_IP = kwargs.get("host_server_ip", HOST_SERVER_IP)
|
SERVER_PORT = kwargs.get("port", SERVER_PORT)
|
||||||
# HOST_SERVER_PORT = kwargs.get("host_server_port", HOST_SERVER_PORT)
|
HOST_SERVER_IP = kwargs.get("host_ip", HOST_SERVER_IP)
|
||||||
|
HOST_SERVER_PORT = kwargs.get("host_port", HOST_SERVER_PORT)
|
||||||
|
|
||||||
@sio.event
|
@sio.event
|
||||||
async def connect():
|
async def connect():
|
||||||
await sio.emit('register', {'name': server_name, 'ip': SERVER_IP, 'port': SERVER_PORT})
|
await sio.emit('register', {'name': SERVER_NAME, 'ip': SERVER_IP, 'port': SERVER_PORT})
|
||||||
print("Announced server to host")
|
print("Announced server to host")
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
@ -60,7 +58,12 @@ async def announce_server(**kwargs):
|
|||||||
|
|
||||||
await main()
|
await main()
|
||||||
|
|
||||||
def announce_server_decorator(task):
|
|
||||||
|
|
||||||
|
def announce_server(task=None, **outer_kwargs):
|
||||||
|
if task is None:
|
||||||
|
return lambda f: announce_server(f, **outer_kwargs)
|
||||||
|
|
||||||
@wraps(task)
|
@wraps(task)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
async def main(*args, **kwargs):
|
async def main(*args, **kwargs):
|
||||||
@ -68,7 +71,7 @@ def announce_server_decorator(task):
|
|||||||
host_block_thread = loop.run_in_executor(None, task)
|
host_block_thread = loop.run_in_executor(None, task)
|
||||||
|
|
||||||
# Announce the server to the host
|
# Announce the server to the host
|
||||||
await announce_server(name='test')
|
await _announce_server(**outer_kwargs)
|
||||||
|
|
||||||
# Wait for host_block to finish
|
# Wait for host_block to finish
|
||||||
await host_block_thread
|
await host_block_thread
|
||||||
@ -76,23 +79,3 @@ def announce_server_decorator(task):
|
|||||||
|
|
||||||
return asyncio.run(main())
|
return asyncio.run(main())
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
# def announce_server_decorator(**outer_kwargs):
|
|
||||||
# def decorator(host_block_function):
|
|
||||||
# @wraps(host_block_function)
|
|
||||||
# def wrapper(*args, **kwargs):
|
|
||||||
|
|
||||||
# async def main(*args, **kwargs):
|
|
||||||
# loop = asyncio.get_event_loop()
|
|
||||||
# host_block_thread = loop.run_in_executor(None, host_block_function, *args, **kwargs)
|
|
||||||
|
|
||||||
# # Announce the server to the host
|
|
||||||
# await announce_server(**outer_kwargs)
|
|
||||||
|
|
||||||
# # Wait for host_block to finish
|
|
||||||
# await host_block_thread
|
|
||||||
|
|
||||||
# return asyncio.run(main(*args, **kwargs))
|
|
||||||
|
|
||||||
# return wrapper
|
|
||||||
# return decorator
|
|
@ -2,6 +2,8 @@ from eden.block import Block
|
|||||||
from eden.datatypes import Image
|
from eden.datatypes import Image
|
||||||
from eden.hosting import host_block
|
from eden.hosting import host_block
|
||||||
|
|
||||||
|
from announce import announce_server, get_ip_address
|
||||||
|
|
||||||
## eden <3 pytorch
|
## eden <3 pytorch
|
||||||
from torchvision import models, transforms
|
from torchvision import models, transforms
|
||||||
import torch
|
import torch
|
||||||
@ -55,9 +57,8 @@ def do_something(config):
|
|||||||
pil_image = Image(pil_image)
|
pil_image = Image(pil_image)
|
||||||
return {"value": value, "index": index, "label": label, 'image': pil_image}
|
return {"value": value, "index": index, "label": label, 'image': pil_image}
|
||||||
|
|
||||||
from announce import announce_server_decorator
|
|
||||||
|
|
||||||
@announce_server_decorator#(name="example_block", port=5656)
|
@announce_server(name='resnet50', port=5656, host_ip="192.168.1.113", host_port=4999, ip=get_ip_address())
|
||||||
def run_host_block():
|
def run_host_block():
|
||||||
host_block(
|
host_block(
|
||||||
block=eden_block,
|
block=eden_block,
|
||||||
|
Loading…
Reference in New Issue
Block a user