Author: KirkMcDonald
Date: 2008-01-05 00:58:29 +0000 (Sat, 05 Jan 2008)
New Revision: 750
Added:
trunk/pysoy/scripts/_eventloop.py
Modified:
trunk/pysoy/scripts/__init__.py
trunk/pysoy/src/_core-common/_eventLoop.pxi
trunk/pysoy/src/_core-common/_init.pxi
trunk/pysoy/src/_datatypes/AsyncQueue.pxi
trunk/pysoy/src/actions/Callback.pxi
Log:
Working Callback action.
Modified: trunk/pysoy/scripts/__init__.py
===================================================================
--- trunk/pysoy/scripts/__init__.py 2008-01-04 22:16:11 UTC (rev 749)
+++ trunk/pysoy/scripts/__init__.py 2008-01-05 00:58:29 UTC (rev 750)
@@ -32,3 +32,7 @@
import textures
import transports
import widgets
+
+import _eventloop
+_eventloop.EventLoop().start()
+#print "EventLoop started."
Added: trunk/pysoy/scripts/_eventloop.py
===================================================================
--- trunk/pysoy/scripts/_eventloop.py (rev 0)
+++ trunk/pysoy/scripts/_eventloop.py 2008-01-05 00:58:29 UTC (rev 750)
@@ -0,0 +1,12 @@
+import threading
+from _core import get_queue
+
+class EventLoop(threading.Thread):
+ def run(self):
+ queue = get_queue()
+ #print "EventLoop.run(): Have queue, starting loop."
+ #print "EventLoop.run(): Queue:", repr(queue)
+ while 1:
+ cb = queue.pop()
+ #print "EventLoop.run(): Got callback:", cb
+ cb()
Modified: trunk/pysoy/src/_core-common/_eventLoop.pxi
===================================================================
--- trunk/pysoy/src/_core-common/_eventLoop.pxi 2008-01-04 22:16:11 UTC (rev
749)
+++ trunk/pysoy/src/_core-common/_eventLoop.pxi 2008-01-05 00:58:29 UTC (rev
750)
@@ -28,17 +28,34 @@
_queue = soy._datatypes.AsyncQueue()
cdef soy._datatypes.AsyncQueue _get_queue():
- stdio.printf("_get_queue()\n")
+ #stdio.printf("_get_queue()\n")
return _queue
+def get_queue():
+ return <object>_get_queue()
+
cdef void _eventLoop() :
cdef void* callb
while (1) :
callb = _queue._pop()
stdio.printf("_eventloop: got callback: %p\n", callb)
stdio.printf("_eventloop: callback is callable? %d\n",
<int>hasattr((<object>callb), "__call__"))
+ if not py.PyEval_ThreadsInitialized():
+ stdio.printf("_eventloop: Threads not initialized, getting lock\n")
+ py.PyEval_InitThreads()
+ else:
+ stdio.printf("_eventloop: Threads initialized, getting lock\n")
+ py.PyEval_AcquireLock()
+ stdio.printf("_eventloop: GIL acquired.\n")
+ _windows.lock()
+ stdio.printf("_eventloop: Have _windows lock.\n")
# Now to get this working:
- #(<object>callb)()
+ (<object>callb)()
+ stdio.printf("_eventloop: Function called.\n")
+ _windows.unlock()
+ stdio.printf("_eventloop: _windows lock released.\n")
+ py.PyEval_ReleaseLock()
+ stdio.printf("_eventloop: GIL released.\n")
py.Py_DECREF(<object>callb)
stdio.printf("_eventloop: Reference count decremented\n")
Modified: trunk/pysoy/src/_core-common/_init.pxi
===================================================================
--- trunk/pysoy/src/_core-common/_init.pxi 2008-01-04 22:16:11 UTC (rev
749)
+++ trunk/pysoy/src/_core-common/_init.pxi 2008-01-05 00:58:29 UTC (rev
750)
@@ -33,7 +33,7 @@
launched = py.PyThread_start_new_thread( <void ((*)(void (*)))> _coreLoop, \
<void *> &threadid )
- eventthread = 2
- launched = py.PyThread_start_new_thread( <void ((*)(void (*)))> _eventLoop, \
- <void *> &eventthread )
+ #eventthread = 2
+ #launched = py.PyThread_start_new_thread( <void ((*)(void (*)))> _eventLoop,
\
+ # <void *> &eventthread )
_init()
Modified: trunk/pysoy/src/_datatypes/AsyncQueue.pxi
===================================================================
--- trunk/pysoy/src/_datatypes/AsyncQueue.pxi 2008-01-04 22:16:11 UTC (rev
749)
+++ trunk/pysoy/src/_datatypes/AsyncQueue.pxi 2008-01-05 00:58:29 UTC (rev
750)
@@ -17,6 +17,8 @@
#
# $Id$
+cimport py
+
cdef class AsyncQueue :
'''GLib AsyncQueue
@@ -33,4 +35,11 @@
glib.g_async_queue_push(self._asyncqueue, data)
cdef void* _pop(self) :
- return glib.g_async_queue_pop(self._asyncqueue)
+ with nogil:
+ return glib.g_async_queue_pop(self._asyncqueue)
+
+ def pop(self):
+ cdef object obj
+ obj = <object>self._pop()
+ py.Py_DECREF(obj)
+ return obj
Modified: trunk/pysoy/src/actions/Callback.pxi
===================================================================
--- trunk/pysoy/src/actions/Callback.pxi 2008-01-04 22:16:11 UTC (rev
749)
+++ trunk/pysoy/src/actions/Callback.pxi 2008-01-05 00:58:29 UTC (rev
750)
@@ -27,11 +27,11 @@
cdef void _perform(self, unsigned int _duration):
cdef soy._datatypes.AsyncQueue _queue
- stdio.printf("Callback._perform\n")
+ #stdio.printf("Callback._perform\n")
py.Py_INCREF(self._callback)
- stdio.printf("Callback._perform: Incremented reference count\n")
+ #stdio.printf("Callback._perform: Incremented reference count\n")
_queue = soy._core._get_queue()
- stdio.printf("Callback._perform: Got queue: %p\n", <void *>_queue)
+ #stdio.printf("Callback._perform: Got queue: %p\n", <void *>_queue)
_queue._push(<void *>self._callback)
- stdio.printf("Callback._perform: Done.\n")
+ #stdio.printf("Callback._perform: Done.\n")
_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn