Movatterモバイル変換
[0]ホーム
[Python-Dev] Create a synthetic stdout for Windows?
Mark HammondMarkH@ActiveState.com
Mon, 8 Jan 2001 15:00:01 -0800
> Limiting the code to pythonw.exe instead of trying to install> it in python20.dll was supposed to prevent damage to the use> of Python in servers. Since pythonw.exe is a Windows (GUI) program,> I am assuming there is a screen.Sometimes _no_ screen at all is wanted - ie, no main GUI window, and noconsole window. pythonw is used in this case. COM uses pythonw.exe in justthis way, and when executed by DCOM, it will be executed in a context wherethe user can not see any such dialog.However, I would be happy to ensure the correct command-line is used toprevent this behaviour in this case.Indeed, in _every_ case I use pythonw.exe I would disable this - but Iaccept that other users have simpler requirements.> Having said that, you may be right that there is some way to> hang on a dialog box which can not be seen. It depends on what> MessageBox() and GetForegroundWindow() actually do. If it seems> that this patch has merit, I would be grateful if you would review> the code to look for issues of this type.There will be no issues in the code - it is just that Win2k will execute ina different "workspace" (I think that is the term). This is identical tothe problem of a service attempting to display a messagebox - the code isperfect and works perfectly - just in a context where noone can see it, ordismiss it.> > I would prefer to see a decent API for extracting error and traceback> > information from Python. On the other hand, I _do_ see the problem for> > "newbies" trying to use pythonw.exe.>> There could be an API added to the winstdout module such as> msg = winstdout.GetMessageText()> which would return saved text, control its display etc.I was thinking more of a "Py_GetTraceback()", which would return a completeexception string.Thus, embedders could write code similar to: whatever = Py_BuildValue(...); ret = PyObject_Call(foo, whatever); ... if (!ok) { char *text = Py_GetTraceback(); MsgBox(text); }Thus, with only a small amount of work, they have _complete_ control overthe output. However, I agree this doesnt really solve pythonw.exe'sproblems.> I do not view winstdout as a "newbie" feature, but rather a> generally useful C-language addition to Python.Hrm. I dont believe a commercial app, for example, would find thissuitable - they would roll their own solution.Hence I see this purely for newbie users. Advanced users have completecontrol now - a simple try/except block around their main code, and you arepretty good. A builtin module for displaying a messagebox is as robust asan experienced user needs to emulate this, IMO.> I guess I am saying, perhaps incorrectly, that the mechanism provided> will make further redirection of sys.stdout unnecessary 99% of the> time.Yes, I disagree here. IMO it is no good for a commercial, real app. As Isaid, I see this as a feature so the newbie will not believe pythonw.exe isbroken. Advanced users can already do similar things themselves.> Experimentation shows that Python composes tracebacks and> error messages a line or partial line at a time. That is, you can> not display each call to printf(), but must wait until the system is> idle to be sure that multiple calls to printf() are complete. So this> forces you to use the idle processing loop, not rocket science but> at least inconvenient.What "idle processing loop"?> And the only source of stdout/err is tracebacks,> error messages and the "print" statement. What would you do with> these in a Windows program except display an "OK" dialog box?Log the error to a file, and display a "friendly" dialog - possibly offeringto automatically submit a support request/bug report.The casual user is going to be _very_ scared by a Python traceback. This isa sin of a similar magnitude to those crappy applications with unhandled VBexceptions.IMO, nothing looks more unprofessional than an app that displays an internalVB error message. Python is no different IMO. For real applications, thereis a good chance that the majority of your users have never heard of Python.Thus, I don't believe your solution suitable for the real, professional,commercial user. However, I agree that your solution does not prevent thisuser doing the "right thing"...But all this does keep me believing this is a "newbie" helper.>> If someone out there knows of a different example of sys.stdout> redirection in use in the real world, it would be helpful if> they would describe it. Maybe it could be incorporated.Sure. Komodo to a file with a friendly dialog (sometimes ;-).Pythonwin actually attempts a few things first - eg, not every exceptionPythonwin casues at startup should be logged.Python services write unhandled errors to the event log.I don't believe I have worked on 2 projects with the same requirementhere!!!Mark.
[8]ページ先頭