0

I am trying to learn threading, following is my code:

import threading, saspy

def sas_session(sas_string):
    sas=saspy.SASsession()
    sas.submit(sas_string)
    sas._endsas()       

if __name__ == "__main__":

    sas_string1='data aa.para_001;\n start = datetime(); \n slept=sleep(rand("Uniform")+10,1);\n ending=start+slept;\nrun;'

    t1 = threading.Thread(target=sas_session, args=(sas_string1,)) 

    t1.start()    
    t1.join()

And I got error message:

Using SAS Config named: iomcom
Exception in thread Thread-3832:
Traceback (most recent call last):
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Myself\.conda\envs\Myself\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\Myself\.conda\envs\Myself\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "U:\python_projects\multi_thread\code.py", line 38, in sas_session
    sas=saspy.SASsession()
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\saspy\sasbase.py", line 448, in __init__
    self._io = SASSessionCOM(sascfgname=self.sascfg.name, sb=self, **kwargs)
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\saspy\sasiocom.py", line 200, in __init__
    self.pid = self._startsas()
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\saspy\sasiocom.py", line 215, in _startsas
    factory = dynamic.Dispatch('SASObjectManager.ObjectFactoryMulti2')
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\win32com\client\dynamic.py", line 127, in Dispatch
    IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

Exception ignored in: <function SASSessionCOM.__del__ at 0x0000022E2F5B8438>
Traceback (most recent call last):
  File "C:\Users\Myself\.conda\envs\Myself\lib\site-packages\saspy\sasiocom.py", line 203, in __del__
    if self.adodb.State == self.STATE_OPEN:
AttributeError: 'SASSessionCOM' object has no attribute 'adodb'

What does this error message mean? One thing needs mention is that

sas.submit(sas_string)

will take a long time to finish, probably about 10 seconds. I guess this is a blocking process. Could this be the reason?

plr108
  • 1,201
  • 11
  • 16
datapy
  • 81
  • 3
  • It's not even making it to `sas.submit()`. It's failing on `saspy.SASsession()` – jordanm Jan 31 '20 at 20:01
  • Possibly relevant: https://stackoverflow.com/a/26753031/1032785 – jordanm Jan 31 '20 at 20:02
  • @jordanm thank you, it worked, But i don't understand anything about this fix. Can you elaborate? I will wait a while and see if there is anyone could give a more detailed explanation. Thanks again – datapy Jan 31 '20 at 20:42
  • I can't elaborate because I have never done any development on Windows. I just googled the "CoInitialize has not been called." error message. – jordanm Jan 31 '20 at 20:44

0 Answers0