Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:38:13+00:00 2026-06-14T19:38:13+00:00

I have a GUI python program and a simple error logging system via import

  • 0

I have a GUI python program and a simple error logging system via

import sys
sys.stderr = open("err.log", "w")

and it works mostly fine. The one problem I have is that whenever I encounter a run-time error using Windows 7 and Python 2.7.3, the file err.log gets written only after I close the program. Reading related issues I gather I’d need to perform flush() and os.fsync() to sys.stderr after the error, but I don’t know how to do that easily.

One way would perhaps be to perform flush/fsync after every possible point in the program where a run-time error is possible, but this is obviously not a good solution. The main reason for using this error logging is debugging, so by definition I can’t really know beforehand where I’d need to flush other than at all the possible places where a run-time error is possible. Since there are a lot of such places I’d prefer not to have to try/catch every one of them.

I’m using PyGTK, so there is no main loop visible to me in which I could do the flush/fsync.

Is there any way to tell Python to always perform flush and fsync after an error, or does anyone have other ideas how to solve this (minor) problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:38:16+00:00Added an answer on June 14, 2026 at 7:38 pm

    I agree with syhpoon: using logging for logging. But if you really need your arrangement, look at the third buffering argument to open to disable it:

    If the buffering argument is given, 0 means unbuffered, 1 means line
    buffered, and larger numbers specify the buffer size. The preferred
    way to open a file is with the builtin open() function.

    I tried this and it works. In a Python session:

    >>> a = open('/tmp/bar', 'w')
    >>> a.write('hi\n')
    

    And in another term window:

    $ cat /tmp/bar
    $
    

    Then I re-ran the experiment with buffering disabled:

    >>> a = open('/tmp/bar', 'w', 0)
    >>> a.write('hi\n')
    

    And:

    $ cat /tmp/var
    hi
    $
    

    So use logging, but if not, see if just disabling buffering will give you what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python program with a wxpython GUI and some command line parameters.
I have a python program that implements pygtk for GUI. I have it running
I'm trying to start perfmon and another program that have GUI's through a python
I have written a python program with a PyQt GUI that, using the imaplib,
I have a problem with a gui in python, the program executes the command
I've written a simple GUI program in python using Tkinter. Let's call this program
I'm writing an python program (gui in gtk) (linux btw.) I want to have
I have a GUI program which should also be controllable via CLI (for monitoring).
I have a Python program to plot a simple graph in using a custom
I have a Python/wxPython program where the GUI is the main thread and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.