8
8
:copyright: (c) 2013-present by Abhinav Singh and contributors.
9
9
:license: BSD, see LICENSE for more details.
10
10
"""
11
- import socket
12
11
import logging
13
12
import argparse
14
- import threading
15
13
import multiprocessing
16
14
17
15
from multiprocessing import connection
18
- from multiprocessing .reduction import send_handle
19
16
20
- from typing import Any , Optional , List , Tuple
17
+ from typing import Any , Optional , List
21
18
22
- from .work import Work
23
19
from .remote import RemoteExecutor
24
20
25
- from ..connection import TcpClientConnection
26
- from ..event import EventQueue , eventNames
21
+ from ..event import EventQueue
27
22
28
23
from ...common .flag import flags
29
24
from ...common .constants import DEFAULT_NUM_WORKERS , DEFAULT_THREADLESS
@@ -83,7 +78,7 @@ def __init__(
83
78
# Threadless worker communication states
84
79
self .work_queues : List [connection .Connection ] = []
85
80
self .work_pids : List [int ] = []
86
- self .work_locks : List [multiprocessing .synchronize .Lock ] = []
81
+ self .work_locks : List [' multiprocessing.synchronize.Lock' ] = []
87
82
# List of threadless workers
88
83
self ._workers : List [RemoteExecutor ] = []
89
84
self ._processes : List [multiprocessing .Process ] = []
@@ -95,59 +90,6 @@ def __enter__(self) -> 'ThreadlessPool':
95
90
def __exit__ (self , * args : Any ) -> None :
96
91
self .shutdown ()
97
92
98
- @staticmethod
99
- def delegate (
100
- worker_pid : int ,
101
- work_queue : connection .Connection ,
102
- work_lock : multiprocessing .synchronize .Lock ,
103
- conn : socket .socket ,
104
- addr : Optional [Tuple [str , int ]],
105
- unix_socket_path : Optional [str ] = None ,
106
- ) -> None :
107
- """Utility method to delegate a work to threadless executor pool."""
108
- with work_lock :
109
- # Accepted client address is empty string for
110
- # unix socket domain, avoid sending empty string
111
- # for optimization.
112
- if not unix_socket_path :
113
- work_queue .send (addr )
114
- send_handle (
115
- work_queue ,
116
- conn .fileno (),
117
- worker_pid ,
118
- )
119
- conn .close ()
120
-
121
- @staticmethod
122
- def start_threaded_work (
123
- flags : argparse .Namespace ,
124
- conn : socket .socket ,
125
- addr : Optional [Tuple [str , int ]],
126
- event_queue : Optional [EventQueue ] = None ,
127
- publisher_id : Optional [str ] = None ,
128
- ) -> Tuple [Work [TcpClientConnection ], threading .Thread ]:
129
- """Utility method to start a work in a new thread."""
130
- work = flags .work_klass (
131
- TcpClientConnection (conn , addr ),
132
- flags = flags ,
133
- event_queue = event_queue ,
134
- upstream_conn_pool = None ,
135
- )
136
- # TODO: Keep reference to threads and join during shutdown.
137
- # This will ensure connections are not abruptly closed on shutdown
138
- # for threaded execution mode.
139
- thread = threading .Thread (target = work .run )
140
- thread .daemon = True
141
- thread .start ()
142
- work .publish_event (
143
- event_name = eventNames .WORK_STARTED ,
144
- event_payload = {'fileno' : conn .fileno (), 'addr' : addr },
145
- publisher_id = publisher_id or 'thread#{0}' .format (
146
- thread .ident ,
147
- ),
148
- )
149
- return (work , thread )
150
-
151
93
def setup (self ) -> None :
152
94
"""Setup threadless processes."""
153
95
if self .flags .threadless :
0 commit comments