[issue32184] pdb/ipdb is not usable on Linux (which works on Windows) from a single multiprocessing.Process when the main process is stuck at process.join()

nartes report at bugs.python.org
Thu Nov 30 16:05:40 EST 2017


nartes <serega.belarus at gmail.com> added the comment:

https://gist.github.com/efe828a7bbac97e02a7d83d2a2d78540

import io
import os
import sys
import multiprocessing


class B(multiprocessing.Process):
    @classmethod
    def _my_thread(self, a, b):
        print("Class method as a separate process entry point. (%s, %s)" % (a, b))

    def __init__(self, glock, *args, **kwargs):
        multiprocessing.Process.__init__(self, *args, **kwargs)

        self.glock = glock

    def run(self):
        try:
            sys.stdin = os.fdopen(0, 'r')
            sys.stdout = os.fdopen(1, 'w')

            self._run()
        except Exception as e:
            raise e
        finally:
            print("Sort of a process destructor, PID = %s" % os.getpid())
            for s in [sys.stdin, sys.stdout]:
                if s is not None and\
                   hasattr(s, 'close'):
                    s.close()

    def _run(self):
        print("Hello, World!")


class A:
    def __init__(self):
        self.glock = multiprocessing.Lock()

    def run(self):
        jobs = []
        for k in range(3):
            jobs.append(B(self.glock))
            #jobs.append(B(self.glock, None, None, None))
        jobs.append(multiprocessing.Process(
            target=B._my_thread,
            args=("one", "two")))

        for j in jobs:
            j.start()

        for j in jobs:
            j.join()


if __name__ == '__main__':
    A().run()

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32184>
_______________________________________


More information about the Python-bugs-list mailing list