cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

print(flush = True) not working

tanjil
New Contributor III

Hello,

I have the following minimum example working example using multiprocessing:

from multiprocessing import Pool
 
files_list = [('bla', 1, 3, 7), ('spam', 12, 4, 8), ('eggs', 17, 1, 3)]
 
 
def f(t):
  print('Hello from child process', flush = True)
  
  name, a, b, c = t
  return (name, a + b + c)
 
def main():
  pool = Pool(processes=3) # set the processes max number 3  
  result = pool.map(f, files_list)
  pool.close()
  pool.join()
  print('end')
  print(result)
 
if __name__ == "__main__":
  main()

However, I cannot get anything from the child process to print. The aim is use the text for debugging purposes in the future. Any idea why this does not work or if there are any alternative solution to this? Thank you.

2 REPLIES 2

Debayan
Esteemed Contributor III
Esteemed Contributor III

Hi, Do you receive any error when you say it is not working?

tanjil
New Contributor III

No errors are generated. The code executes successfully, but there the print statement for "Hello from child process" does not work.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!