473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python threading

I am wondering what happens to a thread in python in relation to
win32com extensions.

If I create a new thread, that uses the Dispatch method from win32com,
what happens to the memory allocated in that thread when the thread is
done. Will the Dispatch release the memory it created, or will the
memory remain?

The problem rises from the fact that Dispatch does not seem to release
memory correctly every time. If I include the commands in a thread by
themselves, will the thread clean up ALL memory it used after it is
done?

I did try the pythoncom.CoUni tialize() to release memory, but it
doesn't seem to work (it does work about 30-45 seconds after the
command is run).

Any input is greatly appreciated (on the thread issue or how to use
the pythoncom.CoUni tiliaze() to make it release memory right away).

Thank you in advance!

Mar 8 '07 #1
3 3464
En Thu, 08 Mar 2007 14:25:02 -0300, <te*****@gmail. comescribió:
I am wondering what happens to a thread in python in relation to
win32com extensions.

If I create a new thread, that uses the Dispatch method from win32com,
what happens to the memory allocated in that thread when the thread is
done. Will the Dispatch release the memory it created, or will the
memory remain?

The problem rises from the fact that Dispatch does not seem to release
memory correctly every time. If I include the commands in a thread by
themselves, will the thread clean up ALL memory it used after it is
done?
All threads share the same memory space, there is not a "per-thread"
memory allocator, if that's what you are thinking.
Perhaps you hold a reference to some objects in the Thread object? Or you
still keep the Thread object itself?
I did try the pythoncom.CoUni tialize() to release memory, but it
doesn't seem to work (it does work about 30-45 seconds after the
command is run).
I don't understand what you say here.
What means "it doesn't seem to work" and "it does work 30 seconds after"?
Any input is greatly appreciated (on the thread issue or how to use
the pythoncom.CoUni tiliaze() to make it release memory right away).
What memory do you want to release "right away"?

--
Gabriel Genellina

Mar 9 '07 #2
On Mar 8, 6:15 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
En Thu, 08 Mar 2007 14:25:02 -0300, <test...@gmail. comescribió:
All threads share the same memory space, there is not a "per-thread"
memory allocator, if that's what you are thinking.
Perhaps you hold a reference to some objects in the Thread object? Or you
still keep the Thread object itself?
That is what I was thinking. A per-thread memory allocator of some
sort. What I need is run a lot of commands from a COM object that can
be run independently. There commands leak memory, so when the command
finishes, the memory consumption jumps to 800MBs or so. Which begs the
question, if I initialize the COM object in a separate thread and run
the command, does finishing the thread clean up any and all memory the
thread used or not. The output of each thread would actually be a file
on disk, therefore there is no need to pass any data between the
threads and the main program.
I did try the pythoncom.CoUni tialize() to release memory, but it
doesn't seem to work (it does work about 30-45 seconds after the
command is run).

I don't understand what you say here.
What means "it doesn't seem to work" and "it does work 30 seconds after"?
pythoncom.CoUni nitialize(), if I am not mistaken, releases a COM
object (and therefore the memory it uses I assume). When the command
is run (in PythonWin for example), the memory is not released but
persists for quite a while. Using my watch and the Task Manager in
Windows I can see that the memory is released approximately 30 seconds
AFTER I run the pythoncom.CoUni nitialize() command is run.
What memory do you want to release "right away"?
The memory I want to release is the memory the COM object used (the
one initialized with the win32com Dispatch command). The "right-away"
is not much of an issue, but if I can release it before I run each
command from the COM object that leaks memory, it would be nice.
Running upwards to 800MBs of RAM for one 500 line python script seems
a little bit too much for me.

Thank you for your reply Gabriel. If you have any more input, I would
greatly appreciate it.
Mar 9 '07 #3
En Fri, 09 Mar 2007 00:38:55 -0300, <te*****@gmail. comescribió:
pythoncom.CoUni nitialize(), if I am not mistaken, releases a COM
object (and therefore the memory it uses I assume).
Not exactly. *You* must release the COM object (usually assigning None to
all references to it). CoUninitialize releases all system resources held
by the COM application, unloads DLLs, and so; it *may* release all COM
objects but I'm not sure.
When the command
is run (in PythonWin for example), the memory is not released but
persists for quite a while. Using my watch and the Task Manager in
Windows I can see that the memory is released approximately 30 seconds
AFTER I run the pythoncom.CoUni nitialize() command is run.
If it is eventually released, you don't have a problem, right?
And, if it will be needed again after a while (when you run the next
command), it looks better this way.
There are many layers on memory management: the OS manages 4K pages that
are mapped on the process address space; the C runtime suballocates such
pages as memory blocks; Python itself has two levels of memory allocation
(and I don't know the details). It's not easy to know exactly how much
memory is actually used; I think the Python runtime, once it allocates a
memory block, never releases it to the OS (remaining as a free block,
available for further usage).

And in general, DLLs are *not* unloaded as soon as its usage count goes to
0; there is certain delay. (I don't remember, but I think there is a
registry key called DLLUnloadTime or something). The idea is to avoid
removing it from memory just to load it again a few moments later, so the
unloading is delayed for a few seconds. You may be seeing this effect.
>What memory do you want to release "right away"?

The memory I want to release is the memory the COM object used (the
one initialized with the win32com Dispatch command). The "right-away"
is not much of an issue, but if I can release it before I run each
command from the COM object that leaks memory, it would be nice.
Running upwards to 800MBs of RAM for one 500 line python script seems
a little bit too much for me.
Let's see if I can understand the problem. You run multiple commands on a
COM object, one after another. The COM object is buggy and leaks some
memory. You run each command on a separate thread, with a CoInitialize(),
waiting for completion, and a CoUninitialize( ) at the end. Memory usage
grows to 800MB when you invoke each command, but if you wait enough time
after the thread finalizes, memory usage goes down to normal. After that,
you run the next command, and so on.
Or do you wait until the whole program finalizes, and 30 seconds after
that, memory usage drops?

--
Gabriel Genellina

Mar 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
6771
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace, dynamic typing, and that it is interpreted - not compiled. These three put python under fire and cause...
19
6495
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread interrupt is a very primitive functionality for stopping a blocked thread.
7
1507
by: kanzen | last post by:
I keep telling my friends that Python rocks. Now it's time to put my money where my mouth is. I'm about to start writing a server for a phone based game. It needs to handle simlpe requests from some Java code running on the phone at a fairly low transaction rate. There will also be a simple web site allowing users to edit preferences and so forth. I have just enough Python experience to decide that I prefer it over Java for this job. It'll...
3
1496
by: David Harrison | last post by:
I am working on an application on Mac OS X that calls out to python via PyImport_ImportModule(). I find that if the imported module creates and starts a python thread, the thread seems to be killed when the import of the module is complete. Is this expected? Does python have to be in control to allow threads to run? Would it be better to arrange things such that the file is processed using PyRun_SimpleFile? David S. Harrison
0
1775
by: Samuel M. Smith | last post by:
I can build python 2.4.2 from source on the embedded linux box when I nfs mount and boot a full debian distribution. The embedded box also has stripped down linux distribution in onboard flash. My goal is to run python from the stripped down linux in onboard flash. I can successfully install python to the onboard flash when booted to the nfs version by using make install with $DESTDIR set to the onboard flash mounted directory
1
8524
by: Carl J. Van Arsdall | last post by:
Hey everyone, I know I've posted several questions regarding python and python's parallel capabilities so bear with me as I've never attempted to incite discussion. However, today I'm interested in sparking discussion over having an OpenMP style of interface in python. For those of you familiar with OpenMP, its a pragmatic api for parallelizing software. For more information I invite anyone to do some google searches, there's a...
9
1869
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this CPU-intensive work in another thread, but of course this won't work because of Python's GIL. There's a lot of past discussion on this, and I want to bring it up again because with the work on Python 3000, I think it is worth trying
0
1560
by: Ling | last post by:
I am using boost.python to wrap C++ function which includes directmusic libraries to simply play the midi, but lots of linkage errors "error LNK2001: unresolved external symbol". I wonder if it is possible to work with DirectX - directmusic libs. Are there any ways to wrap it? *********************compilation errors ************************* msvc.link.dll bin\msvc-7.1\debug\threading-multi\playmusic.pyd bin \msvc-7.1\debu...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.