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 6788551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:29:57+00:00 2026-05-26T17:29:57+00:00

I’m running into a problem with the following Python 3.2.2 code. The code is

  • 0

I’m running into a problem with the following Python 3.2.2 code. The code is an attempt to do some timing tests of another application I’m testing. The idea is to have another script (of any variety) get passed into the timer program and make some changes to the environment. That script should run in a separate thread, so that I can start timing from the start of the script instead of the end. The rest of this script times the application’s reaction to that script. I’ve attempted to draw from the threading module documentation to create this, and I’m confident that I’ve read it thoroughly, but I’m consistently running into the following error using this code:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python32\lib\threading.py", line 669, in start
    if not self._initialized:
AttributeError: 'str' object has no attribute '_initialized'

Here’s the thread class definition.

import threading, ...

class AsyncScript(threading.Thread):
    def __init__(self, s):
        self.script = s
    def run(self):
        print ("Beginning script...")
        try:
            os.system("cmd /k " + self.script)
        except:
            sys.exit("Error running script " + self.script)

This is called elsewhere in the script by AsyncScript.start(options.script), where the options class contains the options passed into the script (using the argparse module.)

Any ideas about what I might be doing wrong here?


Okay, an update. The following (stripped-down) version of the code DOES work, and I’m honestly not sure why — I don’t see the difference.

import threading

class AsyncScript(threading.Thread):
    def __init__(self, s):
        threading.Thread.__init__(self)
        self.script = s
    def run(self):
        print("This would run script " + self.script)

AsyncScript("sample script path string").start()

Output is, appropriately,

This would run script sample script path string

Aside from the inclusion of threading.Thread.__init__(self), which I had previously included in earlier versions of this code without success, I’m not really sure what’s different here. What am I missing?

  • 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-05-26T17:29:57+00:00Added an answer on May 26, 2026 at 5:29 pm

    You don’t need to use threads if you run the script in a separate process anyway. Use subprocess instead of os.system().

    You don’t need to subclass Thread to create a thread:

    Thread(target=func, args=func_args).start()
    

    I’m not really sure what’s different here. What am I missing?

    There are two differences:

    1. AsyncScript.start(options.script) vs. AsyncScript(options.script).start().

      AsyncScript is a class object. AsyncScript(options.script) is an instance of that class.

      AsyncScript.start(options.script) calls an unbound .start method. It expects its first argument to be an AsyncScript instance not a string options.script. The correct way to call a method is obj.method(). In your case obj = AsyncScript(options.script).

    2. Presense of threading.Thread.__init__(self) in the AsyncScript.__init__() method.

      If you don’t call threading.Thread.__init__(self) then Thread’s attributes such as _initialized are not created/defined.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.