Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75837

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

From Peter Otten <__peter__@web.de>
Subject Re: AttributeError: 'module' object has no attribute 'fork'
Date 2014-08-07 09:00 +0200
Organization None
References <7bd83ac7-17e6-49c2-b5c7-3236c900d005@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.12720.1407394838.18130.python-list@python.org> (permalink)

Show all headers | View raw


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 ;)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

AttributeError: 'module' object has no attribute 'fork' Satish ML <satishmlwizpro@gmail.com> - 2014-08-06 23:44 -0700
  Re: AttributeError: 'module' object has no attribute 'fork' Peter Otten <__peter__@web.de> - 2014-08-07 09:00 +0200
    Re: AttributeError: 'module' object has no attribute 'fork' Roy Smith <roy@panix.com> - 2014-08-07 07:49 -0400
      Re: AttributeError: 'module' object has no attribute 'fork' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-08 02:56 +1000
        Re: AttributeError: 'module' object has no attribute 'fork' Rustom Mody <rustompmody@gmail.com> - 2014-08-07 22:19 -0700
          Re: AttributeError: 'module' object has no attribute 'fork' Rustom Mody <rustompmody@gmail.com> - 2014-08-07 22:35 -0700
          Re: AttributeError: 'module' object has no attribute 'fork' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-08 15:48 +1000
            Re: AttributeError: 'module' object has no attribute 'fork' Rustom Mody <rustompmody@gmail.com> - 2014-08-08 00:17 -0700
              Re: AttributeError: 'module' object has no attribute 'fork' Chris Angelico <rosuav@gmail.com> - 2014-08-08 17:32 +1000

csiph-web