Skip to content

Commit b49fcbd

Browse files
authored
[BaseRemoteExecutor] Base executor for processing work remotely (#1050)
* Abstract out FD based work implementation * No need of local/remote abstractions * fix type * Add `BaseLocalExecutor` * Fix lint and tests * Add a `BaseRemoteExecutor`
1 parent c3b06f1 commit b49fcbd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

proxy/core/work/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .pool import ThreadlessPool
1616
from .work import Work
1717
from .local import BaseLocalExecutor
18+
from .remote import BaseRemoteExecutor
1819
from .delegate import delegate_work_to_pool
1920
from .threaded import start_threaded_work
2021
from .threadless import Threadless
@@ -27,4 +28,5 @@
2728
'delegate_work_to_pool',
2829
'start_threaded_work',
2930
'BaseLocalExecutor',
31+
'BaseRemoteExecutor',
3032
]

proxy/core/work/remote.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
proxy.py
4+
~~~~~~~~
5+
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
6+
Network monitoring, controls & Application development, testing, debugging.
7+
8+
:copyright: (c) 2013-present by Abhinav Singh and contributors.
9+
:license: BSD, see LICENSE for more details.
10+
"""
11+
import asyncio
12+
from typing import Any, Optional
13+
from multiprocessing import connection
14+
15+
from .threadless import Threadless
16+
17+
18+
class BaseRemoteExecutor(Threadless[connection.Connection]):
19+
"""A threadless executor implementation which receives work over a connection."""
20+
21+
def __init__(self, *args: Any, **kwargs: Any) -> None:
22+
super().__init__(*args, **kwargs)
23+
self._loop: Optional[asyncio.AbstractEventLoop] = None
24+
25+
@property
26+
def loop(self) -> Optional[asyncio.AbstractEventLoop]:
27+
if self._loop is None:
28+
self._loop = asyncio.get_event_loop_policy().get_event_loop()
29+
return self._loop
30+
31+
def work_queue_fileno(self) -> Optional[int]:
32+
return self.work_queue.fileno()
33+
34+
def close_work_queue(self) -> None:
35+
self.work_queue.close()

0 commit comments

Comments
 (0)