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 documentation can be improved #55282

Closed
roysmith mannequin opened this issue Jan 31, 2011 · 8 comments
Closed

threading.Thread documentation can be improved #55282

roysmith mannequin opened this issue Jan 31, 2011 · 8 comments
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@roysmith
Copy link
Mannequin

roysmith mannequin commented Jan 31, 2011

BPO 11073
Nosy @rhettinger, @pitrou, @bitdancer, @briancurtin

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 2011-01-31.14:40:18.494>
created_at = <Date 2011-01-31.01:42:50.737>
labels = ['type-feature', 'docs']
title = 'threading.Thread documentation can be improved'
updated_at = <Date 2011-01-31.14:40:18.492>
user = 'https://bugs.python.org/roysmith'

bugs.python.org fields:

activity = <Date 2011-01-31.14:40:18.492>
actor = 'pitrou'
assignee = 'docs@python'
closed = True
closed_date = <Date 2011-01-31.14:40:18.494>
closer = 'pitrou'
components = ['Documentation']
creation = <Date 2011-01-31.01:42:50.737>
creator = 'roysmith'
dependencies = []
files = []
hgrepos = []
issue_num = 11073
keywords = []
message_count = 8.0
messages = ['127566', '127568', '127569', '127581', '127583', '127597', '127600', '127601']
nosy_count = 6.0
nosy_names = ['rhettinger', 'roysmith', 'pitrou', 'r.david.murray', 'brian.curtin', 'docs@python']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue11073'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

@roysmith
Copy link
Mannequin Author

roysmith mannequin commented Jan 31, 2011

The documentation for the threading.Thread constructor says:

"target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called."

This could be improved by explicitly stating that target is called in a static context. As written, it takes a bit of thought (and experimentation) to be sure of that.

@roysmith roysmith mannequin assigned docspython Jan 31, 2011
@roysmith roysmith mannequin added the docs Documentation in the Doc dir label Jan 31, 2011
@bitdancer
Copy link
Member

I have no idea what "a static context" means, so it wouldn't make it any clearer to me. Can you explain further what your confusion is?

@bitdancer bitdancer added the type-feature A feature request or enhancement label Jan 31, 2011
@roysmith
Copy link
Mannequin Author

roysmith mannequin commented Jan 31, 2011

What I meant was whether target should be declared as @staticmethod or not.

@bitdancer
Copy link
Member

I still don't understand. I haven't used threading much, but I don't believe I've ever used a static method with it.

@rhettinger
Copy link
Contributor

Roy, it's not clear what you're after. What is it that you think is special about the way the target is called?

@roysmith
Copy link
Mannequin Author

roysmith mannequin commented Jan 31, 2011

Here's the code I ended up writing:

class Foo():
   def __init__(self):
       self.thread = Thread(target=Foo.runner, args=[self])
       self.thread.start()

   @staticmethod
   def runner(self):
      # blah, blah, blah

It was not immediately clear from the documentation if my runner() method should be declared static or not. In retrospect, it must be (since this can be used with target functions which are not class methods at all), but it took a bit of thought to get from what the documentation said (i.e. 'callable object to be invoked by the run() method') to that conclusion.

It seems to me the documentation could be a bit more explicit that your target does not get called as a method of some object. Changing the text to read, "static function or other callable object" would remove any such confusion.

It could be that some of my confusion is due to my previously working with a C++ threading package where the thread runner functions *were* class methods. Still, it seems like the potential for other people to be similarly confused exists and a little tweaking of the documentation text would help.

@briancurtin
Copy link
Member

It was not immediately clear from the documentation if my runner() method should be declared static or not.

The doc doesn't mention static methods at all, and my uses and others that I've seen have never used static methods.

@pitrou
Copy link
Member

pitrou commented Jan 31, 2011

You don't have to use any staticmethod here (actually, staticmethod is an anti-pattern in Python). Just write:

class Foo():
   def __init__(self):
       self.thread = Thread(target=self.runner)
       self.thread.start()

   def runner(self):
      # blah, blah, blah

@pitrou pitrou closed this as completed Jan 31, 2011
@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
docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants