Skip to content

[BaseRemoteExecutor] Base executor for processing work remotely #1050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 23, 2022
Merged
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
2 changes: 2 additions & 0 deletions proxy/core/work/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .pool import ThreadlessPool
from .work import Work
from .local import BaseLocalExecutor
from .remote import BaseRemoteExecutor
from .delegate import delegate_work_to_pool
from .threaded import start_threaded_work
from .threadless import Threadless
Expand All @@ -27,4 +28,5 @@
'delegate_work_to_pool',
'start_threaded_work',
'BaseLocalExecutor',
'BaseRemoteExecutor',
]
35 changes: 35 additions & 0 deletions proxy/core/work/remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
Network monitoring, controls & Application development, testing, debugging.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import asyncio
from typing import Any, Optional
from multiprocessing import connection

from .threadless import Threadless


class BaseRemoteExecutor(Threadless[connection.Connection]):
"""A threadless executor implementation which receives work over a connection."""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self._loop: Optional[asyncio.AbstractEventLoop] = None

@property
def loop(self) -> Optional[asyncio.AbstractEventLoop]:
if self._loop is None:
self._loop = asyncio.get_event_loop_policy().get_event_loop()
return self._loop

def work_queue_fileno(self) -> Optional[int]:
return self.work_queue.fileno()

def close_work_queue(self) -> None:
self.work_queue.close()