I am trying to implement tcp 'echo server'. Simple material:
- The client sends a message to the server.
- Server receives message
- The server converts the message to uppercase.
- The server sends the modified message to the client
- The client prints the response.
This worked, so I decided to parallelize the server; make it able to handle multiple clients at once. Since most Python interpreters have a GIL, multithreading will not reduce it. I had to use multiprocesses ... And boy, this is where things went down.
I am using Windows 10 x64 and a WinPython costume with Python 3.5.2 x64.
My idea is to create a socket, initialize it (connect and listen), create subprocesses and pass the socket to the children. But for the sake of love ... I can not do this work, my subprocesses die almost instantly. At first, I had problems with the "swinging" of the socket ... Therefore, I worked a little with the search and thought that this was a problem. So I tried passing my socket through the multiprocessing queue through the pipe, and my last attempt was forkpickling and passed it as a byte object at the time the processing was created. Nothing works.
Can someone shed some light here? Tell me what's wrong? Perhaps the whole idea (socket separation) is bad ... And if so, PLEASE tell me how I can achieve my original goal: to allow my server to ACTIVELY process several clients at once (on Windows) (donβt tell me about streaming, we are all know that python threads don't cut it.
It is also worth noting that no files are created by the debug function. I believe that no process was long enough to start it.
Typical output of my server code (only the difference between the runs is the process numbers):
Server is running... Degree of parallelism: 4 Socket created. Socket bount to: ('', 0) Process 3604 is alive: True Process 5188 is alive: True Process 6800 is alive: True Process 2844 is alive: True Press ctrl+c to kill all processes. Process 3604 is alive: False Process 3604 exit code: 1 Process 5188 is alive: False Process 5188 exit code: 1 Process 6800 is alive: False Process 6800 exit code: 1 Process 2844 is alive: False Process 2844 exit code: 1 The children died... Why god? WHYYyyyyy!!?!?!?
Server Code:
# Imports import socket import packet import sys import os from time import sleep import multiprocessing as mp import pickle import io
edit: fixed signature "listen". My processes still die instantly.
edit2: The cmidi user indicated that this code really works on Linux; so my question is: how can I "make this work" on Windows?
python multithreading windows networking sockets
Trauer
source share