AttributeError: 'module' object has no attribute 'fork'

Peter Otten __peter__ at web.de
Thu Aug 7 03:00:23 EDT 2014


Satish ML wrote:

> Hi,
> 
> Code:
> import os, time
> def child(pipeout):
>     zzz = 0
>     while True:
>         time.sleep(zzz)
>         msg = ('Spam %03d' % zzz).encode()
>         os.write(pipeout, msg)
>         zzz = (zzz+1) % 5
> def parent():
>     pipein, pipeout = os.pipe()
>     if os.fork() == 0:
>         child(pipeout)
>     else:
>         while True:
>             line = os.read(pipein, 32)
>             print('Parent %d got [%s] at %s' % (os.getpid(), line,
>             time.time()))
> parent()
> 
> Output:
> Traceback (most recent call last):
>   File "C:/Python34/pipe1.py", line 17, in <module>
>     parent()
>   File "C:/Python34/pipe1.py", line 11, in parent
>     if os.fork() == 0:
> AttributeError: 'module' object has no attribute 'fork'
> 
> Why does this error appear? Module os provides fork(). How to solve this
> problem? Kindly help.

Quoting <https://docs.python.org/dev/library/os.html#os.fork>:

"""
os.fork()
Fork a child process.
...
Availability: Unix.
"""

You are using the wrong operating system ;)




More information about the Python-list mailing list