Android. Can't import multiprocessing.

989 views
Skip to first unread message

Yurij Mikhassiak

unread,
Apr 11, 2013, 11:08:30 AM4/11/13
to kivy-...@googlegroups.com
My program works ok in linux. Tried to run it in android with kivy 1.5.1 installed.


Part of info from logcat:

I/python  (17717): Initialize Python for Android
I/python  (17717): ['/data/data/org.kivy.pygame/files/lib/python2.7/site-packages', '/data/data/org.kivy.pygame/files/lib/site-python']
I/python  (17717): Android path ['/data/data/org.kivy.pygame/files/lib/python27.zip', '/data/data/org.kivy.pygame/files/lib/python2.7', '/data/data/org.kivy.pygame/files/lib/python2.7/lib-dynload', '/data/data/org.kivy.pygame/files/lib/python2.7/site-packages', '/mnt/sdcard/kivy/XYZ controller', '/data/data/org.kivy.pygame/files/lib/python2.7/site-packages/PIL']
I/python  (17717): Android kivy bootstrap done. __name__ is __main__
I/python  (17717): Run user program, change dir and execute main.py
I/python  (17717): Traceback (most recent call last):
I/python  (17717):   File "main.py", line 3, in <module>
...
I/python  (17717):     import multiprocessing as mp
I/python  (17717):   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/multiprocessing/__init__.py", line 84, in <module>
I/python  (17717): ImportError: No module named _multiprocessing
I/python  (17717): Python for android ended.



I can't understand where is "/home/tito/" folder and why multiprocessing  module doesn't work. Can anybody give advice how to fix it? 

Akshay Arora

unread,
Apr 11, 2013, 11:14:51 AM4/11/13
to kivy-...@googlegroups.com
The folder-name is just a symlink, don't worry about that.

Multiprocessing isn't supported on android. There were a few attempts to get it to work,
 however it turns out android doesn't allow/like multiprocessing.

You are welcome to try it out yourself though, maybe you'll have more luck.
Take a look at building a recipe for it under python-for-android.

Best Regards


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Yurij Mikhassiak

unread,
Apr 11, 2013, 11:42:38 AM4/11/13
to kivy-...@googlegroups.com
I see py4a have multiprocessing support:
but I am not sure I know how to use it code. I am just making first steps into programming...and python is only language i "know" :(
Is there any hope it will be fixed anyhow? or I need to rewrite big part of my program?






Четвер, 11 квітня 2013 р. 18:14:51 UTC+3 користувач qua-non написав:

Yurij Mikhassiak

unread,
Apr 11, 2013, 2:03:23 PM4/11/13
to kivy-...@googlegroups.com
After instalation of sl4a's python for android I see that in /sdcard/com.googlecode.pythonforandroid/extras/python we have multiprocessing folder with __init__.pyc allot of other .pyc files. 
I also have _multiprocessing.so in /sdcard/com.googlecode.pythonforandroid/python_r16.zip/python 2.6/lib-dynload 
Is it somehow possible to import this/other module/modules to my app

I really need this module :(

Regards, Yurij

Gabriel Pettier

unread,
Apr 11, 2013, 7:08:40 PM4/11/13
to kivy-...@googlegroups.com
I tried a lot, and believe me, it would be better for you to find an
alternative, multiprocessing require os level functions that android
don't provide, and won't ever provide, according to the android
developpers. I put some of the details of my attempt here
http://blog.tshirtman.fr/2012/11/13/debugging-python-for-android-with-gdb
if you are interested, but don't lose too much of your time onto this.

Also, i didn't look much into the sl4a code you point to, but tito did,
and says that it's just a copy of the code from python, without fixing
anything, and that it won't help, if he says this, i'm willing to
believe him, as he usually knows better than me.

On Thu, Apr 11, 2013 at 11:03:23AM -0700, Yurij Mikhassiak wrote:
> After instalation of sl4a's python for android I see that in *
> /sdcard/com.googlecode.pythonforandroid/extras/python* we have *multiprocessing
> folder* with __init__.pyc allot of other .pyc files.
> I also have *_multiprocessing.so* *in*/sdcard/com.googlecode.pythonforandroid/python_r16.zip/python 2.6/
> *lib-dynload *
> Is it somehow possible to* import this/other module/modules to my app*?
>
> I really need this module :(
>
> Regards, Yurij
>
>
> >
> > Четвер, 11 квітня 2013 р. 18:14:51 UTC+3 користувач qua-non написав:
> >>
> >> The folder-name is just a symlink, don't worry about that.
> >>
> >> Multiprocessing isn't supported on android. There were a few attempts to
> >> get it to work,
> >> however it turns out android doesn't allow/like multiprocessing.
> >>
> >> You are welcome to try it out yourself though, maybe you'll have more
> >> luck.
> >> Take a look at building a recipe for it under python-for-android.
> >>
> >> Best Regards
> >>
> >>
> >> On Thu, Apr 11, 2013 at 8:38 PM, Yurij Mikhassiak <mikha...@gmail.com>wrote:
> >>
> >>> My program works ok in linux. Tried to run it in android with kivy 1.5.1
> >>> installed.
> >>>
> >>>
> >>> Part of info from logcat:
> >>>
> >>> I/python (17717): Initialize Python for Android
> >>> I/python (17717): ['/data/data/org.kivy.pygame/**
> >>> files/lib/python2.7/site-**packages', '/data/data/org.kivy.pygame/**
> >>> files/lib/site-python']
> >>> I/python (17717): Android path ['/data/data/org.kivy.pygame/**files/lib/python27.zip',
> >>> '/data/data/org.kivy.pygame/**files/lib/python2.7',
> >>> '/data/data/org.kivy.pygame/**files/lib/python2.7/lib-**dynload',
> >>> '/data/data/org.kivy.pygame/**files/lib/python2.7/site-**packages',
> >>> '/mnt/sdcard/kivy/XYZ controller', '/data/data/org.kivy.pygame/**
> >>> files/lib/python2.7/site-**packages/PIL']
> >>> I/python (17717): Android kivy bootstrap done. __name__ is __main__
> >>> I/python (17717): Run user program, change dir and execute main.py
> >>> I/python (17717): Traceback (most recent call last):
> >>> I/python (17717): File "main.py", line 3, in <module>
> >>> ...
> >>> I/python (17717): import multiprocessing as mp
> >>> I/python (17717): File "*/home/tito/*code/python-for-**
> >>> android/build/python-install/**lib/python2.7/multiprocessing/**__init__.py",
> >>> line 84, in <module>
> >>> I/python (17717):* ImportError: No module named _multiprocessing*

Yurij Mikhassiak

unread,
Apr 12, 2013, 4:36:44 AM4/12/13
to kivy-...@googlegroups.com
Thank's for reply. I see you're right. I can import module from py4a but if i try to create new Process i got

V/sl4a.Process$1:135( 4892): Process 4997 exited with result code 1.
E
/sl4a.Relay:157( 4892): Problem while handling incoming data in relay thread
E
/sl4a.Relay:157( 4892): java.io.IOException: session closed

so no hope for using multiple cores in modern devices :( It's a huge disadvantage as it gives us only 1/4 of CPU resourcess we could use this day and even less in future.  
Hope it's only metter of time when someone will find the way to use android services insted of process in multiprocessing for android. 

I will try to rewrite my program to use Treading (hope it works).

Regards, Yurij



Пʼятниця, 12 квітня 2013 р. 02:08:40 UTC+3 користувач tshirtman написав:

Akshay Arora

unread,
Apr 12, 2013, 5:12:06 AM4/12/13
to kivy-...@googlegroups.com
Using Android service is probably a better solution on android for this.

Julien Coron

unread,
Nov 29, 2013, 12:32:42 PM11/29/13
to kivy-...@googlegroups.com
Hello everybody,

There may be a solution to work with multiprocessing :

You may ca do this :


from threading import Thread

class AsyncLoader(Thread):
    def __init__(self, callback, *largs, **kwargs):
        super(AsyncLoader, self).__init__(*largs, **kwargs)
        self.daemon = True
        self.quit = False
        self.callback = callback

    def run(self):
        your_long_time_job()
        self.callback(loadingDone=True)

and you can use you class with :
loader = AsyncLoader(callback = my_callback)
loader.start()

It does not require the multiprocessing module.


Julien
Reply all
Reply to author
Forward
0 new messages