Hi, PyPy hackers,

I am playing with Python translation to C, especially with threads. I
am using start_new_thread function provided by
pypy.module.thread.ll_thread. My example (see mytasks.py in
attachment) works fine. But when I tried to use locks (provided by the
same module), I got an exception during the translation (see
mytasks_err.py for the source code and translation_trace.txt).

End of the trace:
[translation:ERROR]    File
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/database.py",
line 156, in getcontainernode
[translation:ERROR]     node = nodefactory(self, T, container, **buildkwds)
[translation:ERROR]    File
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/node.py", line
860, in opaquenode_factory
[translation:ERROR]     raise Exception("don't know about %r" % (T,))
[translation:ERROR]  Exception: don't know about <struct
RPyOpaque_ThreadLock (opaque)>

I have no idea whats the problem, translation of pypy interpreter with
thread module enabled works perfectly. Maybe it is caused by the fact
that pypy interpreter uses some special annotation policy, is it
possible?

Please, I would be thankful for any suggestions/comments what to do to
make the locks work.

Marek Paška
import pypy.module.thread.ll_thread as th
import time

def run():
	for i in xrange(100):
		print i
		time.sleep(0.1)

def entry_point(argv):
	print "Start."
	t = th.start_new_thread(run, ())
	t2 = th.start_new_thread(run, ())
	print "To sleep"
	time.sleep(10)
	print "Done."
	return 0


def target(driver, args):
	return entry_point, None
import pypy.module.thread.ll_thread as th
import time

lock = th.allocate_lock()

def run():
	for i in xrange(100):
		lock.acquire(True)
		print i
		lock.release()
		time.sleep(0.1)

def entry_point(argv):
	print "Start."
	t = th.start_new_thread(run, ())
	t2 = th.start_new_thread(run, ())
	print "To sleep"
	time.sleep(10)
	print "Done."
	return 0


def target(driver, args):
	return entry_point, None
[EMAIL PROTECTED]:goal$ ./translate.py mytasks_err.py
[translation:info] Translating target as defined by 
../../../../dist/pypy/translator/goal/pygraph_r/fiber/mytasks_err
[cbuild:execute] cc -O3 -fomit-frame-pointer -pthread 
-I/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c 
-I/usr/include/python2.5 -c platcheck_0.c -o platcheck_0.o
[cbuild:execute] cc -O3 -fomit-frame-pointer -pthread 
-I/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c 
-I/usr/include/python2.5 -c module_1.c -o module_1.o
[cbuild:execute] cc -pthread /tmp/usession-dist-11/platcheck_0.o 
/tmp/usession-dist-11/module_cache/module_1.o -o 
/tmp/usession-dist-11/platcheck_0
[translation] translate.py configuration:
[translation] [translate]
[translation]     targetspec = 
../../../../dist/pypy/translator/goal/pygraph_r/fiber/mytasks_err
[translation] translation configuration:
[translation] [translation]
[cbuild:execute] cc -O3 -fomit-frame-pointer -pthread -c check_boehm.c -o 
check_boehm.o
[cbuild:execute] cc -pthread /tmp/usession-dist-11/check_boehm.o -lgc -o 
/tmp/usession-dist-11/check_boehm
[translation:info] Annotating&simplifying...
[translation:info] with policy: pypy.annotation.policy.AnnotatorPolicy
.............+++++++
[translation:info] -- someobjectness  0% (0 of 20 functions polluted by 
SomeObjects)
[translation:info] RTyping...
.............+++++++++++++++++***
[rtyper] specializing: 100 / 210 blocks   (47%)
[rtyper] specializing: 200 / 210 blocks   (95%)
[rtyper] -=- specialized 210 blocks -=-
.............
[rtyper] -=- specialized 85 more blocks -=-
.....
[rtyper] specializing: 300 / 320 blocks   (93%)
[rtyper] -=- specialized 25 more blocks -=-
....
[rtyper] -=- specialized 13 more blocks -=-
[translation:info] lltype back-end optimisations...
[backendopt:inlining] phase with threshold factor: 32.4
[backendopt:inlining] heuristic: 
pypy.translator.backendopt.inline.inlining_heuristic
.............+++++++++++++++++******
[backendopt:inlining] inlined 70 callsites.
[backendopt:malloc] starting malloc removal
.............+
[backendopt:malloc] removed 42 simple mallocs in total
[backendopt:mergeifblocks] starting to merge if blocks
[translation:info] inserting stack checks...
..
[rtyper] -=- specialized 6 more blocks -=-
14 inital roots
[translation:info] inserted 0 stack checks.
[translation:info] Creating database for generating c source...
.........
[rtyper] -=- specialized 21 more blocks -=-
.............+++++++
[rtyper] specializing: 400 / 445 blocks   (89%)
[rtyper] -=- specialized 85 more blocks -=-
[backendopt:inlining] phase with threshold factor: 32.4
[backendopt:inlining] heuristic: 
pypy.translator.backendopt.inline.inlining_heuristic
........
[backendopt:inlining] inlined 10 callsites.
[backendopt:malloc] starting malloc removal
..
[backendopt:malloc] removed 10 simple mallocs in total
[backendopt:mergeifblocks] starting to merge if blocks
...........
[rtyper] -=- specialized 24 more blocks -=-
[Timer] Timings:
[Timer] annotate                       --- 0.8 s
[Timer] rtype_lltype                   --- 2.8 s
[Timer] backendopt_lltype              --- 0.4 s
[Timer] stackcheckinsertion_lltype     --- 0.0 s
[Timer] database_c                     --- 1.2 s
[Timer] ========================================
[Timer] Total:                         --- 5.2 s
[translation:ERROR] Error:
[translation:ERROR]  Traceback (most recent call last):
[translation:ERROR]    File "./translate.py", line 275, in main
[translation:ERROR]     drv.proceed(goals)
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/driver.py", line 810, in 
proceed
[translation:ERROR]     return self._execute(goals, task_skip = 
self._maybe_skip())
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/tool/taskengine.py", line 
116, in _execute
[translation:ERROR]     res = self._do(goal, taskcallable, *args, **kwds)
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/driver.py", line 284, in 
_do
[translation:ERROR]     res = func()
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/driver.py", line 491, in 
task_database_c
[translation:ERROR]     database = cbuilder.build_database()
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/genc.py", line 73, in 
build_database
[translation:ERROR]     db.complete()
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/database.py", line 310, 
in complete
[translation:ERROR]     add_dependencies(node.enum_dependencies())
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/database.py", line 298, 
in add_dependencies
[translation:ERROR]     self.get(value)
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/database.py", line 218, 
in get
[translation:ERROR]     node = self.getcontainernode(container)
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/database.py", line 156, 
in getcontainernode
[translation:ERROR]     node = nodefactory(self, T, container, **buildkwds)
[translation:ERROR]    File 
"/home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/node.py", line 860, in 
opaquenode_factory
[translation:ERROR]     raise Exception("don't know about %r" % (T,))
[translation:ERROR]  Exception: don't know about <struct RPyOpaque_ThreadLock 
(opaque)>
[translation] start debugger...
> /home/data/opt/svnpypy/vanilla-dist/pypy/translator/c/node.py(860)opaquenode_factory()
-> raise Exception("don't know about %r" % (T,))

_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to