On Friday, August 8, 2014 11:18:17 AM UTC+5:30, Steven D'Aprano wrote:
> Rustom Mody wrote:

> > On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote:
> >> Roy Smith wrote:
> >> >  Peter Otten  wrote:
> >> >> os.fork()
> >> >> Fork a child process.
> >> >> ...
> >> >> Availability: Unix.
> >> >> """
> >> >> You are using the wrong operating system ;)
> >> > To be honest, this could be considered a buglet in the os module.  It
> >> > really should raise:
> >> > NotImplementedError("fork() is only available on unix")
> >> > or perhaps even, as Peter suggests:
> >> > NotImplementedError("You are using the wrong operating system")
> >> > either of those would be better than AttributeError.
> >> I disagree. How would you tell if fork is implemented? With the current
> >> behaviour, telling whether fork is implemented or not is simple:
> >> is_implemented = hasattr(os, "fork")
> [...]
> > Surely I am missing something but why not check os.fork before
> > checking os.fork() ?

> Yes, you're missing something. That's what hasattr does.

> But with Roy's suggestion, testing for the existence of os.fork is not
> sufficient, because it will exist even on platforms where fork doesn't
> exist. So testing that os.fork exists is not sufficient to tell whether or
> not you can actually fork.

Windows:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> os.fork

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    os.fork
AttributeError: 'module' object has no attribute 'fork'


Linux:

$ python
Python 2.7.8 (default, Jul  4 2014, 13:08:34) 
[GCC 4.9.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.fork
<built-in function fork>
>>> 


So yes, I continue to miss something...
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to