[Python-au] win32com threading

nigro nigromx at gmail.com
Thu Apr 10 18:54:10 UTC 2008


Hi:

My problem is:

Who I get many Internet Explorer instances in threading environment, this is
my code with all my trials, but in all cases I have many copies af same
instance

import xmlrpclib
import math
import time
import pythoncom
import win32api
import win32com.client
import sys

from threading import Thread
#from mechanize import Browser
from win32com.client import DispatchEx


class TestCarle(Thread):
    def __init__ (self, site, num):
        Thread.__init__(self)
        #self.br = Browser()
        self.site = site
        self.tiempoFiesta = 0
        self.nombre = ""
        self.i = 0
        self.num = num

    def run(self):
        server = xmlrpclib.Server('http://localhost:9001')

        self.nombre = server.get_name()
        self.tiempoFiesta = server.get_time()

        tiempo = self.tiempoFiesta - time.time()
        #print tiempo
        tiempo = tiempo / 1000

        #print tiempo
        print self.nombre

        time.sleep(tiempo)

        sys.coinit_flags = 0
        #pythoncom.CoInitialize()
        #pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
        pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)

        #ie = pythoncom.CoCreateInstance("InternetExplorer.Application",
None,\
        #        pythoncom.CLSCTX_SERVER,
        #        pythoncom.IID_IDispatch)
        #self.ie = Dispatch(ie)

        #a = win32api.ShellExecute(0,None,"iexplore.exe",self.site,None,1)

#internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
        #hwnds = Dispatch(internetExplorerClassIdentity)
        #self.ie = self.hwnds[self.num]
        #self.ie.Navigate("http://www.google.com/search?hl=en&lr=&q=python
";)


        #self.ie = Dispatch("InternetExplorer.Application")
        self.ie = DispatchEx("InternetExplorer.Application")
        self.ie.Visible = 1
        self.ie.Navigate(self.site)

        while self.ie.Busy:
            time.sleep(6)

        #self.ie.document.getElementById("login").value = "37324"
        self.ie.Document.getElementById("login").value = self.nombre
        self.ie.Document.getElementById("B1").click()

        while self.ie.Busy:
            time.sleep(4)

        #print self.ie.document.frames.length
        #print dir(self.ie.Document.frames)

self.ie.Document.frames[0].Document.getElementById("Submit").click()

        letras = ['A','B','C','D']

        for self.i in range(50):
            print "%s, %s" % (self.nombre, self.i)
            while self.ie.Busy:
                print "Esperando"
                time.sleep(4)


self.ie.Document.frames[0].Document.getElementById("radiobutton").value=letras[self.i%4]

self.ie.Document.frames[0].Document.getElementById("radiobutton").Checked =
True

self.ie.Document.frames[0].Document.getElementById("Submit").click()

        pythoncom.CoUninitialize()


Greats in advance
-- 
Eric Galicia Rosas
CETEE
ITAM

msn: eric_galicia at hotmail.com
tel:    56284000 ext 6612
cel:   0445532228865
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/python-au/attachments/20080410/83b7bcdd/attachment.htm 


More information about the python-au mailing list