aioprocessing icon indicating copy to clipboard operation
aioprocessing copied to clipboard

Unable to inherit AioProcess

Open TanyaEleventhGoddess opened this issue 4 years ago • 4 comments

Executing the following code

from aioprocessing import AioProcess

class MyProcessClass(AioProcess):
    pass

results in the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function() argument 1 must be code, not str

I uh... expect to easily be able to override how a class works & his internal functions

TanyaEleventhGoddess avatar Sep 06 '21 22:09 TanyaEleventhGoddess

Use from aioprocessing.process import AioProcess instead. aioprocessing mirrors the multiprocessing library here - the objects exposed from the top-level module namespace are functions, not classes. The actual class is in a sub-module.

dano avatar Sep 07 '21 17:09 dano

Tue, 07 Sep 2021 10:22:16 -0700 dano @.***>:

Use from aioprocessing.process import AioProcess instead. aioprocessing mirrors the multiprocessing library here - the objects exposed from the top-level module namespace are functions, not classes. The actual class is in a sub-module.

I got your intentions, but you see, class inheritance from multiprocessing works in this way too (tested on latest version and even on cpython alpha)

TanyaEleventhGoddess avatar Sep 08 '21 14:09 TanyaEleventhGoddess

@TanyaEleventhGoddess Ah, looks like the implementation of multiprocessing has changed since I created aioprocessing, and no longer uses functions for the top-level imports. In any case, aioprocessing still does use functions, so just use from aioprocessing.process import AioProcess for now.

I'll leave this open for now, I'm not sure it's worth the effort to refactor the library to match what multiprocessing is doing now, but I should at least document the unusual "function instead of class" behavior.

dano avatar Sep 08 '21 14:09 dano

Wed, 08 Sep 2021 07:43:26 -0700 dano @.***>:

@TanyaEleventhGoddess Ah, looks like the implementation of multiprocessing has changed since I created aioprocessing, and no longer uses functions for the top-level imports. In any case, aioprocessing still does use functions, so just use from aioprocessing.process import AioProcess for now.

I'll leave this open for now, I'm not sure it's worth the effort to refactor the library to match what multiprocessing is doing now, but I should at least document the unusual "function instead of class" behavior.

I may be willing to do that, along with proper inheritance support and ability of overriding internal functions, and async coroutines support in child processes, but I'd prefer some help in doing that. What's your opinion?

TanyaEleventhGoddess avatar Sep 13 '21 17:09 TanyaEleventhGoddess