1

I want to make a multiprocessing program that runs concurrently.

So I want my process to keep counting every 5 seconds while another process keeps asking for an input and printing it.

and the process asking for two inputs should be running in an infinite loop because later I want to change it so that every input will be a value of number variable in the first process. (If you have any ideas to help me out with this too, please let me know! I really appreciate it)

This is the code I have and it just gives me EOFError: EOF when reading a line

import os
import time

from multiprocessing import Process

def doubler():
    number =0
    while True:
        proc = os.getpid()
        print('num : {0} by procss id : {1}'.format(number,proc))
        time.sleep(5)

def test():

    while True:
        x = raw_input("input x : ")
        y = raw_input("input y : ")
        print('x = {0}, y = {1}'.format(x,y))


if __name__ == '__main__':
    proc1 = Process(target=doubler)
    proc2 = Process(target=test)
    procs = []
    procs.append(proc1)
    procs.append(proc2)
    proc1.start()
    proc2.start()

    for proc in procs:
        proc.join()

Result ---> EOFError: EOF when reading a line

Rosè
  • 345
  • 2
  • 13

1 Answers1

0

I'm sorry for being a finger prince but I figured this out in stackoverflow : " When you spawn a thread in Python, it closes stdin. You can't use a subprocess to collect standard input. Use the main thread to collect input instead and post them to the Queue from the main thread. It may be possible to pass the stdin to another thread, but you likely need to close it in your main thread. "

This is not what I wrote and instead it's an answer by Karl. F. Python command line input in a process

Rosè
  • 345
  • 2
  • 13