-
Notifications
You must be signed in to change notification settings - Fork 0
concurrency: Add parent's name to new thread's name #197
Conversation
ebb07ed
to
b1133d4
Compare
This can easily explode: In [1]: import threading
In [2]: from easypy.concurrency import concurrent, MultiObject
In [3]: def recurse(depth):
...: print('%s remain, I am %r' % (depth, threading.current_thread().name))
...: if 0 < depth:
...: with concurrent(recurse, depth - 1):
...: pass
...:
In [4]: recurse(3)
3 remain, I am 'MainThread'
2 remain, I am 'MainThread::7F867069D5F8'
1 remain, I am 'MainThread::7F867069D5F8::7F867069DEF0'
0 remain, I am 'MainThread::7F867069D5F8::7F867069DEF0::7F8670842208' We usually want only the first (context) and last (actual thread to filter on) parts. |
Also, this doesn't work for In [6]: MultiObject(range(5)).call(lambda n: print(n, threading.current_thread().name))
0 ThreadPoolExecutor-1_0
1 ThreadPoolExecutor-1_0
2 ThreadPoolExecutor-1_0
3 ThreadPoolExecutor-1_1
4 ThreadPoolExecutor-1_0
Out[6]: <MultiObject[NoneType] (x5/None)> |
This looks like a problem on |
b1133d4
to
3339b1c
Compare
MultiObject uses python's thread-pool framework, which controls the name. We could do that as long as we don't need to monkey-patch anything - I don't want to deal with more breakages due to python version differences. |
self.threadname = kwargs.pop('threadname', None) | ||
if not self.threadname: | ||
current_thread_name = threading.current_thread().name | ||
if current_thread_name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a thread that doesn't have a name?
I think every concurrent
call is going to have a MainThread::
prefix...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't remember seeing something like this, but wanted to be on the safe side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I think the MainThread::
prefix is redundant and shouldn't be there. A concurrent
thread spawned by the main thread should just have its anon-xxx
name with no prefix.
would you fix that for us?
Fixes #174