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

  • SEARCH
  • Home
  • 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 8385857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:23+00:00 2026-06-09T17:46:23+00:00

My plan is whenever a script is run, to take the current time and

  • 0

My plan is whenever a script is run, to take the current time and create a folder for the log files I generate. Each step of the script makes a new log file in this folder.

The issue is, I’m trying to figure out how to use the same folder for the duration of the script. What’s happening now is each time a logger is created it gets the current time then, making a new folder each time.

Here’s what the module looks like:

logger.py

...

CURRENT_TIME = # get current time
LOG_FOLDER = "logs/%s/" % CURRENT_TIME

...

def get_logger(name):
    # Create a log file with the given name in the LOG_FOLDER

What happens is each time I import logger.py it recalculates CURRENT_TIME. I figured the way to avoid this is to do from logger.py import * which executes the code once for all the modules, making them have the same log folder.

The main issue is the script calls other python scripts, spawning new processes and the like. When these new processes import logger, they haven’t imported it yet so they will regenerate CURRENT_TIME.

So what’s a good way to fix this? One solution I thought of is have the logger use a constant folder called temp and when the main script finishes rename it to the current time (or store the current time at the beginning of the script). I don’t really like this solution as if there is an exception or error and the script dies, the folder will remain temp when I want it in that case to be the time of the script so I know when it failed.

  • 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-09T17:46:24+00:00Added an answer on June 9, 2026 at 5:46 pm

    The classic solution would be to use an environment variable which will be shared between your process and all children.

    Demo (save as x.py, warning: will call itself over and over again):

    import os
    import random
    from subprocess import call
    
    def get_logger():
        return os.environ.setdefault("LOG_DIR", logger_name())
    
    def logger_name(): return "log" + str(random.random())
    
    print "Process " + str(os.getpid()) + " uses " + get_logger()
    
    call(["python",  "x.py"])
    

    References: os.environ docs, the concept of environment variables

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

Sidebar

Related Questions

I plan to create an interactive golf score card for my website (XHTML). (Btw.
i am trying to develop a wiki with version history. my plan is: each
So I have this contact script which works great in firefox but whenever anyone
Whenever I start a new software project I spend a good amount of time
I plan on using multiple popups on my website. Every popup will be rendered
I plan to host a site in a shared hosting environment, where multiple developers
I plan to store quite a few pieces of data about my users in
we plan to use TIBCO EMS queues and TIBCO BW listeners on those queues
I plan on building a simple, yet high usage webapp and need to settle
I plan to delete an entire table with over 930,000 rows of data. Which

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.