mirror of https://github.com/nocturn9x/giambio.git
Added some fixes, still just partially working (join issue still there)
This commit is contained in:
parent
b059125991
commit
189ffbaa53
Binary file not shown.
|
@ -35,7 +35,7 @@ class Task:
|
||||||
return self.coroutine.send(None)
|
return self.coroutine.send(None)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<giambio.core.Task({self.coroutine}, {self.status})"
|
return f"<giambio.core.Task({self.coroutine}, {self.status}, {self.joined})"
|
||||||
|
|
||||||
class EventLoop:
|
class EventLoop:
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class EventLoop:
|
||||||
self.to_run = deque() # Scheduled tasks
|
self.to_run = deque() # Scheduled tasks
|
||||||
self.paused = deque() # Paused or sleeping tasks
|
self.paused = deque() # Paused or sleeping tasks
|
||||||
self.selector = DefaultSelector() # Selector object to perform I/O multiplexing
|
self.selector = DefaultSelector() # Selector object to perform I/O multiplexing
|
||||||
self.running = None # This will always point to the currently running coroutine object
|
self.running = None # This will always point to the currently running coroutine (Task object)
|
||||||
self.waitlist = defaultdict(list) # Tasks that want to join
|
self.waitlist = defaultdict(list) # Tasks that want to join
|
||||||
|
|
||||||
@sync_only
|
@sync_only
|
||||||
|
@ -75,16 +75,10 @@ class EventLoop:
|
||||||
if self.running.joined:
|
if self.running.joined:
|
||||||
exceptions[self.running] = has_raised # Errored? Save the exception
|
exceptions[self.running] = has_raised # Errored? Save the exception
|
||||||
else: # If the task is not joined, the exception would disappear, but not in giambio
|
else: # If the task is not joined, the exception would disappear, but not in giambio
|
||||||
print("Traceback (most recent call last):")
|
|
||||||
traceback.print_tb(has_raised.__traceback__)
|
|
||||||
ename = type(has_raised).__name__
|
|
||||||
if str(has_raised):
|
|
||||||
print(f"{ename}: {has_raised}")
|
|
||||||
else:
|
|
||||||
print(has_raised)
|
|
||||||
raise GiambioError from has_raised
|
raise GiambioError from has_raised
|
||||||
self.to_run.extend(self.waitlist.pop(self.running, ()))
|
self.to_run.extend(self.waitlist.pop(self.running, ()))
|
||||||
|
|
||||||
|
|
||||||
def spawn(self, coroutine: types.coroutine):
|
def spawn(self, coroutine: types.coroutine):
|
||||||
"""Schedules a task for execution, appending it to the call stack"""
|
"""Schedules a task for execution, appending it to the call stack"""
|
||||||
|
|
||||||
|
@ -104,7 +98,7 @@ class EventLoop:
|
||||||
self.selector.register(sock, EVENT_READ, self.running)
|
self.selector.register(sock, EVENT_READ, self.running)
|
||||||
|
|
||||||
def want_write(self, sock: socket.socket):
|
def want_write(self, sock: socket.socket):
|
||||||
"""Handler for the 'want_read' event, performs the needed operations to write into the passed socket
|
"""Handler for the 'want_write' event, performs the needed operations to write into the passed socket
|
||||||
asynchronously"""
|
asynchronously"""
|
||||||
|
|
||||||
self.selector.register(sock, EVENT_WRITE, self.running)
|
self.selector.register(sock, EVENT_WRITE, self.running)
|
||||||
|
@ -143,6 +137,7 @@ class AsyncSocket(object):
|
||||||
|
|
||||||
def __init__(self, sock: socket.socket, loop: EventLoop):
|
def __init__(self, sock: socket.socket, loop: EventLoop):
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
|
self.sock.setblocking(False)
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
|
|
||||||
async def receive(self, max_size: int):
|
async def receive(self, max_size: int):
|
||||||
|
|
6
test.py
6
test.py
|
@ -43,5 +43,7 @@ async def echo_server(sock: AsyncSocket, addr: tuple):
|
||||||
logging.info(f"Connection from {addr} closed")
|
logging.info(f"Connection from {addr} closed")
|
||||||
|
|
||||||
|
|
||||||
loop.start(make_srv, ('', 1500))
|
try:
|
||||||
|
loop.start(make_srv, ('', 1500))
|
||||||
|
except giambio.exceptions.GiambioError as error:
|
||||||
|
print(f"Error: {error}")
|
||||||
|
|
Loading…
Reference in New Issue