Search code examples
multiprocessingpython-multiprocessinghy

Example of using hylang with python multiprocessing


I am looking for an example of using python multiprocessing (i.e. a process-pool/threadpool, job queue etc.) with hylang.


Solution

  • The first example from the multiprocessing documentation can be literally translated to Hy like so:

    (import multiprocessing [Pool])
    
    (defn f [x]
      (* x x))
    
    (when (= __name__ "__main__")
      (with [p (Pool 5)]
        (print (.map p f [1 2 3]))))