uqfoundation / pathos

parallel graph management and execution in heterogeneous computing
http://pathos.rtfd.io
Other
1.39k stars 89 forks source link

Using Multiprocess vs. Multiprocessing causes isinstance() to always return False #119

Open Ralithune opened 7 years ago

Ralithune commented 7 years ago

Hello! I am a self-taught python programmer (to frame things) and I just spent the last 2 hours or so troubleshooting a bug I was seeing that turned out to be Multiprocess.

I think the following code might better explain the issue than me typing it out. This is on CentOS 7.3's Python 2.7.5:

#! /usr/bin/python
import multiprocess
import multiprocessing

class Drive(object):
    def __init__(self, osa):
        self.os_address = osa

def gather_os_addresses():
    drive_list = []
    drive_list.append(Drive("/dev/sda"))
    drive_list.append(Drive("/dev/sdb"))
    drive_list.append(Drive("/dev/sdc"))
    return drive_list

def test_pool(pool):
    p = pool.apply_async(gather_os_addresses)
    bail = False
    while not bail:
        bail = True    
        if not p.ready():
            bail = False
        #End if the pool process isn't ready yet
    #End wait for processes to complete loop
    pool.close()
    drive_list = p.get()
    for d in drive_list:
        print "d is type {}, isinstace(d, Drive) is {}".format(type(d), isinstance(d, Drive))

pool = multiprocessing.Pool(5)
print "Using MultiprocessING:"
test_pool(pool)
print ""
print "Using Multiprocess:"
pool = multiprocess.Pool(5)
test_pool(pool)

And the output is:

Using MultiprocessING:
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True

Using Multiprocess:
d is type <class '__main__.Drive'>, isinstace(d, Drive) is False
d is type <class '__main__.Drive'>, isinstace(d, Drive) is False
d is type <class '__main__.Drive'>, isinstace(d, Drive) is False
mgolub2 commented 7 years ago

Further details, when using python 2.7.10, the output is like above. However with python 3.6.2:

Len drive_list is 3
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True

Len drive_list is 3
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True
d is type <class '__main__.Drive'>, isinstace(d, Drive) is True

This is on MacOS 10.13 Beta 7

Ralithune commented 7 years ago

Added Python version to original post

mmckerns commented 5 years ago

Interestingly, this seems to be a moving target. Currently the code fails on: 3.73, 3.6.8, 3.5.7, 3.3.7, 3.2.6, 3.1.5, and 2.7.16... but passes on 3.4.10. I suspect it's related to dill serializing the class object along with the class instance -- which sometimes results errors like __main__.Driver and __main__.Driver being different classes.