Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

Apartments Open for Inspection

It’s time to demonstrate some of these concepts. To do this, we develop three COM objects, each of which support one of the various threading models discussed previously. These COM objects are quite simple and expose only two methods: GetCreatedThreadId() to return the thread ID of the thread that created the object, and GetCurrentThreadId() to return the thread ID of the current thread (that is, the thread receiving the call). If you have read Chapter 12, there will be nothing new in this example. The only points worth mentioning are that we use win32api.GetCurrentThreadId() to obtain the Win32 Thread ID, and that we use a Python base class for the raw COM functionality, and subclasses for the object-specific registration information. The COM objects are implemented in ThreadingModelsServer.py :

# ThreadingModelsServer.py # Python COM objects that demonstrate COM threading models. # # Exposes 3 Python objects, all of which have identical functionality, # but each indicate they support different threading models. import win32api # A Base class for our 2 trivial objects. class ThreadDemoObject: _public_methods_ = [ 'GetCurrentThreadId', 'GetCreatedThreadId' ] def __init__(self): self.created_id = win32api.GetCurrentThreadId() def GetCreatedThreadId(self): return self.created_id def GetCurrentThreadId(self): # Simply return an integer with the Win32 thread ID. return win32api.GetCurrentThreadId() class ThreadApartmentObject(ThreadDemoObject): _reg_threading_ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page