1

I have a Python for .Net (2.7) script that subscribes to an event defined in a .NET assembly. When that event fires and my python-based event handler is called, is my handler executing in Python's main thread or in a worker thread?

...
def MyEventHandler(source, args):
    print 'Received message: ' + args.Message
...
dotNetObject.SomeEvent += MyEventHandler
...

I figured it must be a worker thread but when I put this line of code in the handler:

print threading._active

it only reported the main thread:

{8920: <_MainThread(MainThread, started 8920)>}

How can I tell what thread a given line of Python is executing in?

UPDATE: Okay, I found threading.current_thread(). Outside of my handler it returns:

<_MainThread(MainThread, started 7064)>

while inside my handler it returns

<_DummyThread(Dummy-1, started daemon 7916)>

So is a "DummyThread" a worker thread? Why didn't it show up in threading._active?

Thanks.

1 Answer 1

1

DummyThreads are worker threads and show up in this call:

threading.enumerate()

So, yes, the event handler is executing in a worker thread.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.