Connection Refused on Concurrent connection to openerp with xmlrpc (via python)
<p>I've tried to build a stress test sistem which provide multiple concurent user login. The scheme is 1 thread for 1 user login. But i cant login with multiple user at the same time (concurent).</p>

<p>At the other side, i've tried to login with multiple user in sequential scheme (with thread.lock and thread.release over login method), and it works.</p>

<p>Can i login with multiple user at the same time on python thread scheme like this?</p>

<p>This is my code
(<strong>Updated:</strong>
i've update my code, and now i tried to read via xml_rpc with multithread.
Open Connection/Login is OK, but the i always get the <strong>Failed Return on Reading Method</strong>..
):</p>

<p>This threading class:</p>

<pre><code>class theUser (threading.Thread):
    def __init__(self, threadID, row, dbhost, xml_port, dbuser, dbpassword, dbname):
        threading.Thread.__init__(self)
        self.threadID   = threadID
        self.name       = str(row[0])
        self.pswd       = str(row[1])
        self.msg        = ''
        self.xml_port   = xml_port
        self.params={'dbhost'   : dbhost,
                    'dbuser'    : dbuser,
                    'dbpassword': dbpassword,
                    'dbname'    : dbname,
                    'user'      : str(row[0]),
                    'password'  : str(row[1])
                }

    def run(self):
        try:
            self.sock_common    = xmlrpclib.ServerProxy ('http://%s:%s/xmlrpc/common' % (dbhost, xml_port))
            self.uid = self.sock_common.login(self.params['dbname'], self.name, self.pswd)                    

            self._read_data()

        except:
            return

    def _read_data(self):
        self.ids = [1,2,3,10]
        self.sock_common.execute(self.params['dbname'], self.uid, self.params['password'], 'res.partner', 'read', self.ids, ['name'])            
</code></pre>

<p>This is the main code:</p>

<pre><code>for row in reader:
    print idx, xml_port, row

    if idx == 0:
        header = row

    else:
        # Create new User threads
        thread_ = theUser(idx, row, dbhost, xml_port, dbuser, dbpassword, dbname)

        # Start new User Threads
        thread_.start()

        # Add threads to thread list    
        threads.append(thread_)

    idx += 1
</code></pre>

<p>Please help me..</p>

<p>You forgot <code>xml_port</code> when you create <code>theUser</code>, it should be:  </p>

<pre><code>thread_ = theUser(idx, row, dbhost, xml_port, dbuser, dbpassword, dbname)
</code></pre>

<p>And <code>self.sock_common</code> won't be set if an exception is raised.You can move it to <code>run()</code> function.</p>

<p>To read <code>res.partner</code>: </p>

<pre><code>def _read_data(self):
    self.ids = [1,2,3,10]
    models = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/object' % (dbhost, xml_port))
    res = models.execute(self.params['dbname'], self.uid, self.params['password'], 'res.partner', 'read', self.ids, ['name'])
    print res
</code></pre>

<p>You can check if a given user is permited to read using:  </p>

<pre><code>models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password,
'res.partner', 'check_access_rights',
['read'], {'raise_exception': False})
</code></pre>

<p>If the user can read, it should return <code>true</code>.</p>

<blockquote>
  <p>This script is from <a href="https://www.odoo.com/documentation/8.0/api_integration.html" rel="nofollow">Odoo Web Service API</a></p>
</blockquote>

python multithreading openerp python-multithreading stress-testing