[Pymilter] milter multiprocess (or multithread)

Marco falon at ruparpiemonte.it
Tue Nov 12 07:55:15 EST 2019


Hello pymilter users,

  I would like to ask a question as a beginner on Python.

milter-template.py seems to be an example of multiprocess milter:

https://github.com/sdgathman/pymilter/blob/python3-branch/milter-template.py

For python3 I had to change something, such as BytesIO in place of 
StringIO... but I managed to work with it.

Line 30 says

"# each connection runs in its own thread and has its own myMilter
  # instance."

This is what I want to achieve. I would like to write a milter with a 
TCP socket where each client connection (or mail) open a new process.
The milter make several things, it writes to RedisDB, ask something with 
REST API and finally decides if the mail has to be accepted or rejected.

I would like to manage these operation in parallel, with a process for 
each new mail passed to the milter. Each process doesn't need to wait 
some results from other processes.

But trying this template if I well understand I see that only two 
processes are opened. A master process and one child which handle all 
the connections:

   bt = Thread(target=background)
   bt.start()
   socketname = "/home/stuart/pythonsock"
   timeout = 600
   # Register to have the Milter factory create instances of your class:
   Milter.factory = myMilter
   flags = Milter.CHGBODY + Milter.CHGHDRS + Milter.ADDHDRS
   flags += Milter.ADDRCPT
   flags += Milter.DELRCPT
   Milter.set_flags(flags)       # tell Sendmail which features we use
   print "%s milter startup" % time.strftime('%Y%b%d %H:%M:%S')
   sys.stdout.flush()
   Milter.runmilter("pythonfilter",socketname,timeout)
   logq.put(None)
   bt.join()


uhm...

Could you help me to understand how to achieve the result to open new 
process (milter instance) for every new mail sent to the milter socket? 
Or, alternatively, a new process for every new client (MTA) connected to 
the milter.

Thank you very much for every hints

Kind Regards
Marco


More information about the Pymilter mailing list