Skip to content
Advertisement

patch object spawned in sub-processs

I am using multiprocessing package for crating sub-processes. I need to handle exceptions from sub-process. catch, report, terminate and re-spawn sub-process. I struggle to create test for it.

I would like to patch object which represent my sub-process and raise exception to see if handling is correct. But it looks like that object is patched only in main process and in spawned process is unchanged version. Any ideas how to accomplish requested functionality?

Example:

JavaScript

Advertisement

Answer

you can monkey-patch the object before it is started (it is a bit iffy but you will get actual process running that code)

JavaScript

you could also mock multiprocessing to behave like threading but that is a bit unpredictable

if you want to do it genericly for all objects you can mock the class for another one derived from the original one with only one method overriden

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement