Author: dmeyer
Date: Mon Oct 29 08:05:58 2007
New Revision: 2887
Log:
Create notifier pipe when setting up the mainthread. I hope
this will fix the pipe problem for the future.
Modified:
trunk/base/src/notifier/jobserver.py
trunk/base/src/notifier/reactor.py
trunk/base/src/notifier/thread.py
Modified: trunk/base/src/notifier/jobserver.py
==============================================================================
--- trunk/base/src/notifier/jobserver.py (original)
+++ trunk/base/src/notifier/jobserver.py Mon Oct 29 08:05:58 2007
@@ -129,8 +129,6 @@
self.stopped = False
self.jobs = []
self.name = name
- if not thread._thread_notifier_pipe:
- thread._create_thread_notifier_pipe()
self.start()
Modified: trunk/base/src/notifier/reactor.py
==============================================================================
--- trunk/base/src/notifier/reactor.py (original)
+++ trunk/base/src/notifier/reactor.py Mon Oct 29 08:05:58 2007
@@ -80,10 +80,6 @@
"""
Configure the twisted mainloop to be run using the kaa reactor.
"""
- # start internal wakeup queue
- # FIXME: integrate this better
- if not kaa.notifier.thread._thread_notifier_pipe:
- kaa.notifier.thread._create_thread_notifier_pipe()
reactor = KaaReactor()
from twisted.internet.main import installReactor
installReactor(reactor)
Modified: trunk/base/src/notifier/thread.py
==============================================================================
--- trunk/base/src/notifier/thread.py (original)
+++ trunk/base/src/notifier/thread.py Mon Oct 29 08:05:58 2007
@@ -104,9 +104,8 @@
_thread_notifier_lock.acquire()
_thread_notifier_queue.insert(0, (self, args, kwargs))
if len(_thread_notifier_queue) == 1:
- if not _thread_notifier_pipe:
- _create_thread_notifier_pipe()
- os.write(_thread_notifier_pipe[1], "1")
+ if _thread_notifier_pipe:
+ os.write(_thread_notifier_pipe[1], "1")
_thread_notifier_lock.release()
# FIXME: what happens if we switch threads here and execute
@@ -168,14 +167,6 @@
"""
Start the thread and return an InProgress object.
"""
- if not _thread_notifier_pipe:
- # Make sure the pipe is created in the mainloop _before_ we
- # start the thread. If we do not do that it could be possible
- # that the thread needs to create this and it will add the
- # socket to an already blocking select() which will never
- # wake up on that new socket.
- _create_thread_notifier_pipe()
-
r = InProgress()
self.signals['completed'].connect_once(r.finished)
self.signals['exception'].connect_once(r.exception)
@@ -215,29 +206,30 @@
# process without exec. If you have this pipe, communication will go wrong.
_thread_notifier_pipe = None
-def _create_thread_notifier_pipe():
- global _thread_notifier_pipe
- log.info('create thread notifier pipe')
- _thread_notifier_pipe = os.pipe()
-
- fcntl.fcntl(_thread_notifier_pipe[0], fcntl.F_SETFL, os.O_NONBLOCK)
- fcntl.fcntl(_thread_notifier_pipe[1], fcntl.F_SETFL, os.O_NONBLOCK)
-
- notifier.socket_add(_thread_notifier_pipe[0], _thread_notifier_run_queue)
-
+
def wakeup():
"""
Wake up main thread.
"""
- if not _thread_notifier_pipe:
- _create_thread_notifier_pipe()
- if len(_thread_notifier_queue) == 0:
+ if _thread_notifier_pipe and len(_thread_notifier_queue) == 0:
os.write(_thread_notifier_pipe[1], "1")
def set_current_as_mainthread():
global _thread_notifier_mainthread
+ global _thread_notifier_pipe
_thread_notifier_mainthread = threading.currentThread()
+ # Make sure we have a pipe between the mainloop and threads. Since loop()
+ # calls set_current_as_mainthread it is safe to assume the loop is
+ # connected correctly. If someone calls step() without loop() and
+ # without set_current_as_mainthread inter-thread communication does
+ # not work.
+ if not _thread_notifier_pipe:
+ log.info('create thread notifier pipe')
+ _thread_notifier_pipe = os.pipe()
+ fcntl.fcntl(_thread_notifier_pipe[0], fcntl.F_SETFL, os.O_NONBLOCK)
+ fcntl.fcntl(_thread_notifier_pipe[1], fcntl.F_SETFL, os.O_NONBLOCK)
+ notifier.socket_add(_thread_notifier_pipe[0],
_thread_notifier_run_queue)
def _thread_notifier_run_queue(fd):
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog