Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threading.Thread objects are not reusable after join() #45967

Closed
dweeves mannequin opened this issue Dec 14, 2007 · 4 comments
Closed

threading.Thread objects are not reusable after join() #45967

dweeves mannequin opened this issue Dec 14, 2007 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dweeves
Copy link
Mannequin

dweeves mannequin commented Dec 14, 2007

BPO 1626
Nosy @loewis, @amauryfa
Files
  • unnamed
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-12-14.13:03:54.416>
    created_at = <Date 2007-12-14.12:11:47.379>
    labels = ['invalid', 'type-bug', 'library']
    title = 'threading.Thread objects are not reusable after join()'
    updated_at = <Date 2007-12-14.16:58:06.237>
    user = 'https://bugs.python.org/dweeves'

    bugs.python.org fields:

    activity = <Date 2007-12-14.16:58:06.237>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-12-14.13:03:54.416>
    closer = 'amaury.forgeotdarc'
    components = ['Library (Lib)']
    creation = <Date 2007-12-14.12:11:47.379>
    creator = 'dweeves'
    dependencies = []
    files = ['8953']
    hgrepos = []
    issue_num = 1626
    keywords = []
    message_count = 4.0
    messages = ['58622', '58625', '58627', '58631']
    nosy_count = 3.0
    nosy_names = ['loewis', 'amaury.forgeotdarc', 'dweeves']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1626'
    versions = ['Python 2.5', 'Python 2.4']

    @dweeves
    Copy link
    Mannequin Author

    dweeves mannequin commented Dec 14, 2007

    After a call to join() method on a Threading.thread object,there is no
    way to successfully call start() method on it.

    Indeed, the __started flag is not reset in the theading.Thread join()
    method.
    Since the start() method checks for __started flag , this flag is always
    true after a first start, despite the thread was effectively stopped by
    the join() call

    Since it's perfectly legal to store a threading.Thread object in a
    variable or an object member, i think the join() behaviour is odd
    because it prevents instance reusability.

    @dweeves dweeves mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 14, 2007
    @amauryfa
    Copy link
    Member

    From the documentation:
    http://docs.python.org/dev/library/threading.html#threading.Thread.start
    start() must be called at most once per thread object.

    I think this will not change: when a system thread terminates, you
    cannot restart it; you have to create another thread.
    The same argument applies to threading.Thread. It would be surprising
    that this object can represent multiple system threads.

    You should create and start different Threads each time.

    @dweeves
    Copy link
    Mannequin Author

    dweeves mannequin commented Dec 14, 2007

    Hi Amaury,

    to me,Thread objects are meant to be abstract representation of a processing that will occur in a separate execution unit at thread start time.
    Indeed, that's what the following text (from the link you provided tries to explain)

    "Once a thread object is created, its activity must be started by calling the thread’s start() method. This invokes the run() method in a separate thread of control."

    So, the 'System Thread' is only created at start() call (which is a good implementation choice)
    Moreover, the join() method (when completed) will wait for the System Thread to be disallocated.

    However, the Thread object instance and the processing bound to it are still valid.

    So in an object oriented point of view, (and syntactically too) , it should be valid to reuse the object (and so repeat the processing bound to it) as many times as necessary without the need to create a new instance as long as the Thread object state is not Alive.

    What suprises me , is that the current implementation of threading.Thread (apart from the __started flag behaviour) is compatible with that point of view and i see no limitations (apart that bug) preventing such a use of threads.

    I think the threading API will provide better 'high-level' view if it didn't depend on low level considerations (as the dependency on the existence / reusability of the peer System Thread that will be used to effectively host the code execution)

    Regards,

    Sebastien


    Express yourself instantly with MSN Messenger! Download today it's FREE!
    http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Dec 14, 2007

    I agree with Amaury. This all works exactly as it should work, and will
    not change.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant