I have not tested this on a GUI screen, but...<br>You should be able to assign any class with a .write() method to sys.stdout (and/or sys.stderr) so that normal &quot;print&quot; statements/functions and tracebacks will be sent to that method. I use the trick frequently to get a simple logging facility by assigning a text file -- like:<br>

&lt;code&gt;<br>import sys<br>my_log = open(&#39;my_log_file.txt&#39;,&#39;w&#39;)<br>sys.stdout = my_log<br>print &#39;Hello, Log.&#39;<br>sys.stderr = my_log<br>error = 1 / 0<br>&lt;/code&gt;<br>Is that the kind of &#39;messages&#39; you were thinking about?<br>

--<br>Vernon<br><br><div class="gmail_quote">On Tue, Jun 7, 2011 at 2:00 AM, AndyF. <span dir="ltr">&lt;<a href="mailto:andy_fulstow@hotmail.com">andy_fulstow@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
Thank you Dino<br>
<br>
modifying my Python dispatcher to read<br>
<div class="im"><br>
dispatcher.BeginInvoke(System.Action(lambda *_: function(*args)))<br>
<br>
</div>fixed the problem.  Unfortunately for me, utilising the dispatcher has an<br>
unforseen side effect - the &#39;messages&#39; printed to my console only appear<br>
when the python script exits.<br>
<br>
If I revert the code to bypass all dispatcher code i.e. use the following<br>
<br>
    def write(self, string):<br>
        self.texbox.AppendText(string)<br>
<br>
then I see the messages arrive in real time.<br>
<br>
I have tested launching my PythonEngine class using a thread with both<br>
ApartmentState.STA and MTA but this has no discernible effect.<br>
<br>
Can you offer any explanation, maybe workaround?<br>
<br>
Thanks<br>
<br>
AndyF.<br>
<div><div></div><div class="h5"><br>
<br>
<br>
Dino Viehland wrote:<br>
&gt;<br>
&gt; AndyF wrote:<br>
&gt;&gt; Hi Chaps<br>
&gt;&gt;<br>
&gt;&gt; I have attempted to purloin some of the code shipped with IP in Action<br>
&gt;&gt; and,<br>
&gt;&gt; following issues, I have even gone to the lengths of reading the book!<br>
&gt;&gt;<br>
&gt;&gt; I am getting the error &#39;expect Delegate, got Function&#39; when I use the<br>
&gt;&gt; following code. FYI I am passing in a reference to a WPF textBox so I<br>
&gt;&gt; should<br>
&gt;&gt; have a dispatcher on my UI element<br>
&gt;&gt;<br>
&gt;&gt; I have removed all of the threading pipe reading stuff just to leave<br>
&gt;&gt; &#39;test&#39;<br>
&gt;&gt; code:<br>
&gt;&gt;<br>
&gt;&gt; import System<br>
&gt;&gt; import System.IO<br>
&gt;&gt; import Avacta.Optim.Server.WebServices<br>
&gt;&gt; import Avacta.Optim.Server.DataModel<br>
&gt;&gt; import sys<br>
&gt;&gt; import clr<br>
&gt;&gt; import time<br>
&gt;&gt;<br>
&gt;&gt; from System import Console<br>
&gt;&gt; from System.Threading import Thread, ThreadStart<br>
&gt;&gt;<br>
&gt;&gt; def SetDispatcher(ui_element):<br>
&gt;&gt; global dispatcher # needed else &quot;Exception: &#39;NoneType&#39; object has no<br>
&gt;&gt; attribute &#39;BeginInvoke&#39;&quot;<br>
&gt;&gt; dispatcher = ui_element.Dispatcher<br>
&gt;&gt;<br>
&gt;&gt; def Dispatch(function, *args):<br>
&gt;&gt; dispatcher.BeginInvoke(lambda *_: function(*args))<br>
&gt;&gt;<br>
&gt;&gt; def GetDispatchFunction(function):<br>
&gt;&gt; return lambda *args: Dispatch(function, *args)<br>
&gt;&gt;<br>
&gt;&gt; class ListOutput:<br>
&gt;&gt; def __init__(self, textbox):<br>
&gt;&gt; self.textbox = textbox<br>
&gt;&gt;<br>
&gt;&gt; def write(self, string):<br>
&gt;&gt; Dispatch(self.addText, string) # error: &quot;expect Delegate, got Function&quot;<br>
&gt;&gt; # self.addText(string) # ok works fine w-w/o dispatcher stuff<br>
&gt;&gt;<br>
&gt;&gt; def addText(self, string):<br>
&gt;&gt; textbox.AppendText(string)<br>
&gt;&gt;<br>
&gt;&gt; if textbox != None:<br>
&gt;&gt; listout = ListOutput(textbox)<br>
&gt;&gt; sys.stdout = listout<br>
&gt;&gt; SetDispatcher(textbox)<br>
&gt;&gt;<br>
&gt;&gt; print &quot;Define running&quot;<br>
&gt;&gt; #running = True<br>
&gt;&gt;<br>
&gt;&gt; Thread.Sleep(0)<br>
&gt;&gt; time.sleep(2)<br>
&gt;&gt;<br>
&gt;&gt; print &quot;Start The Comms Thread...&quot;<br>
&gt;&gt; #comms_t = Thread(ThreadStart(run_comms))<br>
&gt;&gt; #comms_t.Start()<br>
&gt;&gt;<br>
&gt;&gt; Thread.Sleep(0)<br>
&gt;&gt; time.sleep(2)<br>
&gt;&gt;<br>
&gt;&gt; Any clues would be greatly appreciated!<br>
&gt;<br>
&gt; The WPF invocation functions just take a type which is typed to &quot;Delegate&quot;<br>
&gt; instead of a type of a specific delegate.  Therefore we don&#39;t know what<br>
&gt; type<br>
&gt; of delegate to create for you automatically.  Instead you can convert the<br>
&gt; Python function into a delegate by calling the delegate type directly,<br>
&gt; e.g.:<br>
&gt;<br>
&gt; dispatcher.BeginInvoke(System.Action(lambda *_: function(*args)))<br>
&gt;<br>
&gt; or you can use another delegate type (e.g. System.Action[object]) with the<br>
&gt; appropriate signature you need.<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt;<br>
&gt;<br>
<br>
</div></div><font color="#888888">--<br>
View this message in context: <a href="http://old.nabble.com/Dispatcher-Problem-tp31782357p31789855.html" target="_blank">http://old.nabble.com/Dispatcher-Problem-tp31782357p31789855.html</a><br>
</font><div class="im">Sent from the IronPython mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</div></div></blockquote></div><br>