kopia lustrzana https://github.com/micropython/micropython-lib
multiprocessing: Add, with bare Process class implementation.
rodzic
4835a37871
commit
fec581f862
|
@ -0,0 +1,20 @@
|
|||
import os
|
||||
|
||||
|
||||
class Process:
|
||||
|
||||
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
|
||||
self.target = target
|
||||
self.args = args
|
||||
self.pid = 0
|
||||
|
||||
def start(self):
|
||||
self.pid = os.fork()
|
||||
if not self.pid:
|
||||
self.target(*self.args)
|
||||
os._exit(0)
|
||||
else:
|
||||
return
|
||||
|
||||
def join(self):
|
||||
os.waitpid(self.pid, 0)
|
|
@ -0,0 +1,15 @@
|
|||
import sys
|
||||
# Remove current dir from sys.path, otherwise distutils will peek up our
|
||||
# module instead of system.
|
||||
sys.path.pop(0)
|
||||
from setuptools import setup
|
||||
|
||||
setup(name='micropython-multiprocessing',
|
||||
version='0.0.1',
|
||||
description='multiprocessing module to MicroPython',
|
||||
url='https://github.com/micropython/micropython/issues/405',
|
||||
author='Paul Sokolovsky',
|
||||
author_email='micro-python@googlegroups.com',
|
||||
license='MIT',
|
||||
install_requires=['micropython-os'],
|
||||
py_modules=['multiprocessing'])
|
|
@ -0,0 +1,9 @@
|
|||
from multiprocessing import Process
|
||||
|
||||
def f(name):
|
||||
print('hello', name)
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = Process(target=f, args=('bob',))
|
||||
p.start()
|
||||
p.join()
|
Ładowanie…
Reference in New Issue