I'm getting AttributeError: 'module' object has no attribute 'fork' when i run my program on windows. How can i fix this?

Viewed 1151

I tried calling the os.fork() in the parent() funtion but yet it gives me the same error.

this is my code:

import os

def child():
    print('Hello from child', os.getpid())
    os._exit(0) # else goes back to parent loop

def parent():
    while True:
        newpid = os.fork()
        if newpid == 0:
            child()
        else:
            print('Hello from parent', os.getpid(), newpid)
        if input() == 'q': break

parent()
1 Answers

os.fork()is only available in Unix. See this.

Related