Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

405 changes: 0 additions & 405 deletions .idea/dbnavigator.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/pythonProject110.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
A custom made event loop with async and await syntax,
background tasks, and custom functions, along with concurrent synchronization.

The selectors module makes this all possible.

https://docs.python.org/3/library/selectors.html

![Screenshot 2024-06-21 125920](https://github.com/bendeez/async_event_loop/assets/127566471/378260f9-9145-49ff-b910-366f1204171f)

```python
from event_loop import EventLoop
from connection import Connection



loop = EventLoop(max_connections=15)

async def scrape_other_website():
results = await loop.gather(Connection("https://www.google.com/"))
return results

async def scrape_website(url):
first_result = await scrape_other_website()
print(first_result)
second_result = await loop.gather(*[Connection(url) for _ in range(10)])
return second_result

async def main(loop):
url = "https://github.com/"
task_1 = loop.create_task(scrape_website(url))
result = await loop.gather(task_1)
print(result)

loop.run(main(loop))

Binary file removed __pycache__/connection.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/event_loop.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/future.cpython-311.pyc
Binary file not shown.
Binary file removed __pycache__/task.cpython-311.pyc
Binary file not shown.
3 changes: 1 addition & 2 deletions connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def initialize_connection(self):
self.get_url_details()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.port == 443:
context = ssl.create_default_context()
self.client = context.wrap_socket(s, server_hostname=self.host)
self.client = ssl.create_default_context().wrap_socket(s, server_hostname=self.host)
self.client.setblocking(False)
else:
self.client = s
Expand Down
3 changes: 1 addition & 2 deletions event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def add_connection(self, connection, fut=None,in_gather=False):
connection.initialize_connection()
if len(self.select_connections) < self.max_connections:
self.select_connections.append(connection)
self.select.register(connection.client, selectors.EVENT_READ | selectors.EVENT_WRITE,
data=connection)
self.select.register(connection.client, selectors.EVENT_READ | selectors.EVENT_WRITE, data=connection)
else:
# limits the amount of concurrent connections
self.connection_queue.put(connection)
Expand Down