ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-win32
python-win32
Re: [python-win32] Threading problem
by Tim Roberts other posts by this author
Apr 19 2006 10:16AM messages near this date
[python-win32] Threading problem | [python-win32] Building pywin32 with the free MS toolkit compiler (Was: Problem with installer for pywin32 with Python 2.5)
On Tue, 18 Apr 2006 15:01:10 +0200 (Central European Daylight Time),
"Aleksandar Cikota" <alexci@[...].net>  wrote:

> I have a problem with threading. 
>   
> 

Why do you think it is a threading problem?  Does this exact program
work if you replace TestThread().start() with TestThread().run()?

Do you know for certain that the MaxIm objects are thread safe?  You're
creating the documents in one thread and using them in another.

> import win32com.client
> import time
> import os
> import threading
> Document = win32com.client.Dispatch('MaxIm.Document')
> Application = win32com.client.Dispatch('MaxIm.Application')
> p = win32com.client.dynamic.Dispatch('PinPoint.Plate')
> class TestThread (threading.Thread):
>     def run (self):
>       path_to_watch = "F:/Images/VRT/"  
>       before = dict ([(f, None) for f in os.listdir (path_to_watch)])
>       while 1:
>         time.sleep(2)
>         after2 = dict ([(f, None) for f in os.listdir (path_to_watch)])
>         added = [f for f in after2 if not f in before]
>   
> 

As a side note, why do you turn these into dicts instead of just leaving
them as lists?  Given your usage, this seems like unnecessary extra
overhead.

And this code can't be right.  If there are multiple new files in the
directory, your "name" string will contain ALL of them, and it's
virtually certain that OpenFile won't know how to handle that.

>         if added:
>                 name= ' ,'.join (added)
>                 if str(name[-3:])=='fit':
>   
> 

The "str" is unnecessary here.  "name" is already a string.

>                             print name
>                             Document.OpenFile('F:/Images/VRT/'+name) 
>                             Document.SaveFile('F:/Images/VRT/'+
> str(name[0:-4])+'.jpg', 6, 1024,2)
>                             Application.CloseAll()
>   
> 

Does CloseAll close the application?  If so, doesn't that make the
Document objects evaporate?  Why don't you create the Document and
Application objects in your inner loop?  There's no sense in forcing an
instance of the application to stick around all the time when it's only
going to be asked to operate occasionally.

>                 before = after2
> TestThread().start()
> 

-- 
Tim Roberts, timr@[...].com
Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32@[...].org
http://mail.python.org/mailman/listinfo/python-win32
Thread:
Aleksandar Cikota
Tim Roberts

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved