2

I made the following script which is almost the same as available here.

from multiprocessing import Process
import time
import sys

def f(n):
    print n
#    sys.stdout.flush()

if __name__ == '__main__':
    f('hello')
    p = Process(target = f, args=('python',))
    p.start()
    p.join()
    time.sleep(2)
    print 'bye'

When i run the script in python IDLE, it outputs :

hello
bye

and not :

hello 
python
bye

But when i run the script in windows terminal it gives the required output. Following the advice here, i tried sys.stdout.flush() as I thought there would be some buffering issues.

How can I get the desired output in the python shell ? Any suggestion is appreciated. I am using Python 2.7.9 [MSC v.1500 64 bit (AMD64)] on win32.

EDIT: I went through the question suggested in the comment. I ran the command python -m idlelib.idle as suggested from the terminal but it opened a python console and a shell. I ran my script through this shell but still the output was shown on the console and not the shell. How can I get the output on the shell directly so that i don't have to run the script from terminal every time when i have to debug using print statement ?

Community
  • 1
  • 1
ShubhamS
  • 53
  • 1
  • 1
  • 5
  • 1
    Possible duplicate of [Can multiprocessing Process class be run from IDLE](http://stackoverflow.com/questions/35293178/can-multiprocessing-process-class-be-run-from-idle) – ppasler Apr 20 '17 at 11:13
  • @ppasler i went through the link. I tried it. The output comes on the python console and not the shell. I want the shell to directly print the content. – ShubhamS Apr 20 '17 at 12:03

0 Answers0