'How to use multiprocessing manager along with socketserver
I'm currently having some issues with trying to have a shared list that runs alongside my server. I'm using threading, socketserver and multiprocessing and wasn't sure if there was a better method out there to do this.
Here's the code for the socket
server = socketserver.ThreadingTCPServer(("", 12333), Handler)
server.daemon_threads = True
threading.Thread(target=server.serve_forever, name="server", daemon=True).start()
Here's my Handler, and where I currently have the process running (I want to move it out of the handler so it can run before there's a connection from a client
class Handler(socketserver.BaseRequestHandler):
def load_files(self, file_l, num_files):
...
def setup(self):
self.event = threading.Event()
self.file_l = Manager().list()
self.num_files = Manager().Value('i', 0)
p1 = Process(target = self.load_files, args= (self.file_l, self.num_files))
p1.start()
def handle(self):
super().handle()
....
I want to be able to load the files into the system before the connection begins, but still have the capability of having the server run while the file loading is happening. I wasn't able to find an answer anywhere else, so any help would be much appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
