Multiprocessing lib Error

23 views
Skip to first unread message

JayH

unread,
Jul 25, 2011, 5:58:51 PM7/25/11
to Py4A
Hi,

I am trying to use pysage (http://code.google.com/p/pysage/) using
Py4A. It looks like it should work.

Here is the sample script
***************************************

from pysage import *
import android

class FoodAvailableMessage(Message):
properties = ['amount']
types = ['i']
packet_type = 101

class Consumer(Actor):
subscriptions = ['FoodAvailableMessage']
def handle_FoodAvailableMessage(self, msg):
print 'Yummy! I had %d pancakes!' %
(msg.get_property('amount'))

import time, random

class Chef(Actor):
def __init__(self):
self.last_sent = time.time()
def update(self):
'''every 2 seconds, this chef makes a random amount of
pancakes'''
if time.time() - self.last_sent > 2.0:
mgr.queue_message_to_group(mgr.PYSAGE_MAIN_GROUP,
FoodAvailableMessage(amount=random.randint(0,10)))
self.last_sent = time.time()

mgr = ActorManager.get_singleton()
mgr.register_actor(Consumer())

if __name__ == '__main__':
droid=android.Android()
mgr.enable_groups()
mgr.add_process_group('chefs', Chef) # spawns a new process
that "ticks" independently
while True:
processed = mgr.tick()
time.sleep(.03)

***************************************

Pysage uses the multiprocessing lib. I am getting the following error
returned:

***************************************
dlopen libpython2.6.so
Traceback (most recent call last):
File "/mnt/sdcard/sl4a/scripts/TestPySage2.py", line 31, in <module>
mgr.add_process_group('chefs', Chef) # spawns a new process
that "ticks" independently
File "/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/
pysage/system.py", line 376, in add_process_group
self._ipc_listen()
File "/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/
pysage/system.py", line 268, in _ipc_listen
self.ipc_transport.listen()
File "/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/
pysage/transport.py", line 265, in listen
self._connection = processing.connection.Listener()
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-
build/output/usr/lib/python2.6/multiprocessing/connection.py",
line 97, in __init__
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-
build/output/usr/lib/python2.6/multiprocessing/connection.py",
line 218, in __init__
File "<string>", line 1, in bind
socket.error: [Errno 1] Operation not permitted
***************************************

*Info about the android system.
Android Virtual Device
Platform 2.2 API Level 8

The web browser is working fine.
If I look at Settings -> Application -> Manage Application ->
Python For Android - Network Communication - Full Internet Access
SL4A- Network Communication - create Bluetooth connections, Full
Internet Access

It could be the AVD. I have not purchased one for development yet. I
was hoping the AVD would do until I made the purchase.

So, I have two questions.
1. Is this an issue with multiprocessing lib? If so, I will need to
build a module using pyprocessing from (http://developer.berlios.de/
projects/pyprocessing) and see if it works.
2. Could someone try it on a real device? If it works on a real
device, then I will make the purchase now.

Thanks,
Jay.

Manuel Naranjo

unread,
Jul 26, 2011, 8:48:21 AM7/26/11
to python-fo...@googlegroups.com

> droid=android.Android()
> mgr.enable_groups()
> mgr.add_process_group('chefs', Chef) # spawns a new process
Here's the problem! Android doesn't have users account support, so you
can't create a new process group. You need a different way to fork your
new process. Just don't try setting the group of the project or user.

Manuel

Jay Herrmann

unread,
Jul 27, 2011, 3:04:45 PM7/27/11
to python-fo...@googlegroups.com
Hi Manuel, 

Thank you.  I will look into this and let you know what I find.

Jay.

JayH

unread,
Jul 29, 2011, 10:22:18 AM7/29/11
to Py4A
Hi,

Well I have had limited success. After contacting the author of the
pysage, he let me know that the groups didn't system groups but were
logical process groups. I also made a suggestion to change the call
to the listener constructor to be
multiprocessing.connection.Listener(family='AF_INET'). This fixed the
socket issue.

Now the issue is as follows

dlopen libpython2.6.so
Traceback (most recent call last):
File "/mnt/sdcard/sl4a/scripts/TestPySage2.py", line 32, in <module>
mgr.add_process_group('chefs', Chef) # spawns a new process
that "ticks" independently
File "/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/
pysage/system.py", line 383, in add_process_group
switch = processing.Value('B', 0)
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-
build/output/usr/lib/python2.6/multiprocessing/__init__.py", line 247,
in Value
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-
build/output/usr/lib/python2.6/multiprocessing/sharedctypes.py", line
23, in
<module> AttributeError: 'module' object has no attribute
'c_wchar'

The ctypes lib module is not recognizing c_wchar. As is seen by the
trace the pysage call is passing a 'B' char. Any ideas as to why this
is happening? And how to fix it?


Jay.

Jay Herrmann

unread,
Jul 29, 2011, 10:30:30 AM7/29/11
to Py4A
Let clarify, I see I have a grammar errors.

Well I have had limited success.  After contacting the author of the
pysage, he let me know that the groups didn't use system groups but were
logical process groups.  He also made a suggestion to change the call

to the listener constructor to be
multiprocessing.connection.Listener(family='AF_INET').  This fixed the
socket issue.

Jay.

Manuel Naranjo

unread,
Jul 29, 2011, 12:13:56 PM7/29/11
to python-fo...@googlegroups.com

> Hi,
>
> Well I have had limited success. After contacting the author of the
> pysage, he let me know that the groups didn't system groups but were
> logical process groups. I also made a suggestion to change the call
> to the listener constructor to be
> multiprocessing.connection.Listener(family='AF_INET'). This fixed the
> socket issue.
What's your source code now?

> <module> AttributeError: 'module' object has no attribute
> 'c_wchar'

This is because we don't have unicode support, 'B' is unsigned byte.

I fixed this problem by doing:

import ctypes
from _ctypes import _SimpleCData

class c_wchar(_SimpleCData):
_type_ = 'c'

def __init__(self, *args, **kwargs):
raise "Not implemented in Android"

ctypes.c_wchar = c_wchar

That fixed the first problem, but raised the next one, which is we don't
have semaphores for multiprocessing in Android as bionic doesn't seem to
have support for it, sorry but I think you will not be able to use
pysage at all.

Manuel

Jay Herrmann

unread,
Jul 29, 2011, 6:29:17 PM7/29/11
to python-fo...@googlegroups.com
Hi,
 
socket issue.
What's your source code now?
I changed the pysage transport.py file in the Class IPCTransport(Transport). I updated the call to processing.connection.Listener(family='AF_INET') where processing is the multiprocessing lib.

    <module>  AttributeError: 'module' object has no attribute
'c_wchar'
This is because we don't have unicode support, 'B' is unsigned byte.

I fixed this problem by doing:

import ctypes
from _ctypes import _SimpleCData

class c_wchar(_SimpleCData):
   _type_ = 'c'

   def __init__(self, *args, **kwargs):
       raise "Not implemented in Android"

ctypes.c_wchar = c_wchar

So did you make this change to multiprocessing lib?? Or Sharedctypes??

That fixed the first problem, but raised the next one, which is we don't have semaphores for multiprocessing in Android as bionic doesn't seem to have support for it, sorry but I think you will not be able to use pysage at all.

So Android in the bionic libc does not semaphores?  So that meaning inter-process communication is not possible?? Or Is it a muttiprocessing lib issue and a different lib may work.

Jay.

Manuel Naranjo

unread,
Aug 2, 2011, 9:16:08 AM8/2/11
to python-fo...@googlegroups.com
El 29/07/11 19:29, Jay Herrmann escribió:
Hi,
 
socket issue.
What's your source code now?
I changed the pysage transport.py file in the Class IPCTransport(Transport). I updated the call to processing.connection.Listener(family='AF_INET') where processing is the multiprocessing lib.
Ok



    <module>  AttributeError: 'module' object has no attribute
'c_wchar'
This is because we don't have unicode support, 'B' is unsigned byte.

I fixed this problem by doing:

import ctypes
from _ctypes import _SimpleCData

class c_wchar(_SimpleCData):
   _type_ = 'c'

   def __init__(self, *args, **kwargs):
       raise "Not implemented in Android"

ctypes.c_wchar = c_wchar

So did you make this change to multiprocessing lib?? Or Sharedctypes??
In your module before importing pysage.



That fixed the first problem, but raised the next one, which is we don't have semaphores for multiprocessing in Android as bionic doesn't seem to have support for it, sorry but I think you will not be able to use pysage at all.

So Android in the bionic libc does not semaphores?  So that meaning inter-process communication is not possible?? Or Is it a muttiprocessing lib issue and a different lib may work.
There's a native IPC in Android called binder you should use. Or you need sockets, but you can't do it with shared pieces of memory.

Manuel



Jay Herrmann

unread,
Aug 3, 2011, 2:27:19 PM8/3/11
to python-fo...@googlegroups.com
Thank you for the information about the binder.  I will check into it.

Jay.
Reply all
Reply to author
Forward
0 new messages