[pywin32-bugs] [ pywin32-Bugs-874096 ] Race condition with genpy.py and stdout
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2004-04-07 05:26:36
|
Bugs item #874096, was opened at 2004-01-10 08:56 Message generated for change (Comment added) made by mhammond You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=874096&group_id=78018 Category: com Group: None Status: Open Resolution: None Priority: 5 Submitted By: David Boreham (dboreham) Assigned to: Nobody/Anonymous (nobody) Summary: Race condition with genpy.py and stdout Initial Comment: I've been investigating a problem for a client of mine where the symptoms were that a generated python file in the ...\win32com\gen_py directory had become corrupted. It looked mostly ok, but contained one line of text which was not Python. I tracked that string down to another part of the application, completely unrelated. Upon investigation I believe that the cause is this code in genpy.py: def generate(self, file, is_for_demand = 0): if is_for_demand: self.generate_type = GEN_DEMAND_BASE else: self.generate_type = GEN_FULL self.file = file oldOut = sys.stdout sys.stdout = file try: self.do_generate() finally: sys.stdout = oldOut self.file = None self.progress.Finished() It's redirecting stdout for the generated python file. In the application this happens underneath a call to gencache.EnsureModule(). Unfortunately the application is concurrently executing another thread which is also writing to stdout. The result is that the two sets of output are intermingled. I guess that it would be possible to refactor the code in genpy.py such that it outputs to a file rather than to stdout (the file could be stdout for cases where the code is run as a standalone utility). I see the checkin comment for version 1.30 suggests that this is a known problem: >Also started a move to "print >>" for the generation. Thanks. ---------------------------------------------------------------------- >Comment By: Mark Hammond (mhammond) Date: 2004-04-07 15:26 Message: Logged In: YES user_id=14198 Yes, this could happen :) I'd love patches to address this. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=874096&group_id=78018 |