Question

Based on an example for forking, I build up this little script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlanydb
import os

def child():
    conn = sqlanydb.connect(uid='dba', pwd='sql', eng='somedb_IQ', dbn='somedb')
    curs = conn.cursor()
    curs.execute("""SELECT * FROM foobaa;""")
    os.exit(0)

def parent():
   while True:
      newpid = os.fork()
      if newpid == 0:
         child()
      else:
         pids = (os.getpid(), newpid)
         print "parent: %d, child: %d" % pids
      if raw_input( ) == 'q': break

parent()

The intention is to do the database action inside a seperate process (big goal later is to run a huge number of queries at the same time).

But when running the script, I'm getting:

parent: 20580, child: 20587
Traceback (most recent call last):
  File "connectiontest.py", line 25, in <module>
    parent()
  File "connectiontest.py", line 19, in parent
    child()
  File "connectiontest.py", line 8, in child
    conn = sqlanydb.connect(uid='dba', pwd='sql', eng='somedb_IQ', dbn='somedb')
  File "/usr/local/lib/python2.6/dist-packages/sqlanydb.py", line 461, in connect
    return Connection(args, kwargs)
  File "/usr/local/lib/python2.6/dist-packages/sqlanydb.py", line 510, in __init__
    self.handleerror(*error)
  File "/usr/local/lib/python2.6/dist-packages/sqlanydb.py", line 520, in handleerror
    eh(self, None, errorclass, errorvalue)
  File "/usr/local/lib/python2.6/dist-packages/sqlanydb.py", line 342, in standardErrorHandler
    raise errorclass(errorvalue)
sqlanydb.OperationalError: Failed to initialize connection object

What did I might miss?

Was it helpful?

Solution 2

The issue seems to don't happen by moving import sqlanydb into child()-methode. So it would look something like:

def child():
    import sqlanydb

    conn = sqlanydb.connect(uid='dba', pwd='sql', dsn='some_db')
    curs = conn.cursor()
    curs.execute("""SELECT * FROM SA100_1_1;""")
    curs.close()
    conn.close()

OTHER TIPS

Since Sybase IQ is based on Sybase ASA, are you sure that you're using the proper keys for the credentials? This (albeit, old) documentation looks like it wants DSN and DSF instead of ENG and DBN.

http://dcx.sybase.com/1101/en/dbprogramming_en11/python-writing-open.html

You need to hack the sqlanydb source to print out the actual error being seen. Whatever the problem is is being masked by a generic OperationalError which is not giving enough information to fix the problem. Line 510 is where you need to add a couple prints to figure out what is (not) going on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top