This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nartes
Recipients nartes
Date 2017-11-30.21:05:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512075940.35.0.213398074469.issue32184@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2017-11-30 21:05:40nartessetrecipients: + nartes
2017-11-30 21:05:40nartessetmessageid: <1512075940.35.0.213398074469.issue32184@psf.upfronthosting.co.za>
2017-11-30 21:05:40narteslinkissue32184 messages
2017-11-30 21:05:40nartescreate