Thread: after application close MS Visual C++ runtime library error occurs

after application close MS Visual C++ runtime library error occurs

From
Peter Irbizon
Date:
Hello, I am using psycopg2 in windows app for example:
import psycopg2
import psycopg2.extras
self.con = psycopg2.connect("dbname= host= user= password= port=");
self.cur = self.con.cursor(cursor_factory=psycopg2.extras.DictCursor)
 
SELECT = "select something" 
self.cur.execute(SELECT)
 
for row in self.cur:
 ...
 
self.cur.close()
self.con.close()
 
But when I click on exit button in application MS Visual C++ runtime library error occurs: This application has requested the runtime to terminate it in unusual way.
What am I doing wrong?

Re: after application close MS Visual C++ runtime library error occurs

From
Peter Irbizon
Date:
Hello Jason,
 
thanks for your questions. I will try to answer:
WinXp Pro, x86, python 2.7 32bit, pygtk, latest version of psycopg2, py/gtk 2.24.0
 
ad  __del__() - No. It closes connections wher at the end of timer interval (every few minutes it checks data in db and closes connections). I am not using SSL mode. But I found out when I import psycopg2 after gtk import it shows that error on exit but when I import psycopg2 before gtk it seems to work fine.
 
example with error:
import pygtk
pygtk.require("2.0")
import gtk
import psycopg2
import psycopg2.extras
example without error:
import psycopg2
import psycopg2.extras
import pygtk
pygtk.require("2.0")
import gtk
 
it is strange but I am happy it works now. however I would like to know if it is bug or not. thanks.
 
--Peter
 
2012/1/11 Jason Erickson <jason.erickson@stickpeople.com>
A few quick questions, then I can try and duplicate the issue:

* What Windows version are you running the program on (ie, XP, Windows 7) and what architecture (x86, x64)?
* What Python GUI framework are you using (and version)?
* What Python version & architecture?
* Are the self.cur.close() and self.con.close() calls inside the __del__() method of your object (ie, are they being called when the object is destroyed, or do you have a method in your object such as 'close' that closes the connections when the button is pressed?
* Are you including/using SSL in your code, via psycopg (by using the sslmode parameter on the connection), and/or by using https in httplib, or including ssl?
* Any other nonstandard lib modules being imported in your code?


-jason


On Wed, Jan 11, 2012 at 7:21 AM, Peter Irbizon <peterirbizon@gmail.com> wrote:
Hello, I am using psycopg2 in windows app for example:
import psycopg2
import psycopg2.extras
self.con = psycopg2.connect("dbname= host= user= password= port=");
self.cur = self.con.cursor(cursor_factory=psycopg2.extras.DictCursor)
 
SELECT = "select something" 
self.cur.execute(SELECT)
 
for row in self.cur:
 ...
 
self.cur.close()
self.con.close()
 
But when I click on exit button in application MS Visual C++ runtime library error occurs: This application has requested the runtime to terminate it in unusual way.
What am I doing wrong?


Re: after application close MS Visual C++ runtime library error occurs

From
Jason Erickson
Date:
A few quick questions, then I can try and duplicate the issue:

* What Windows version are you running the program on (ie, XP, Windows 7) and what architecture (x86, x64)?
* What Python GUI framework are you using (and version)?
* What Python version & architecture?
* Are the self.cur.close() and self.con.close() calls inside the __del__() method of your object (ie, are they being called when the object is destroyed, or do you have a method in your object such as 'close' that closes the connections when the button is pressed?
* Are you including/using SSL in your code, via psycopg (by using the sslmode parameter on the connection), and/or by using https in httplib, or including ssl?
* Any other nonstandard lib modules being imported in your code?


-jason


On Wed, Jan 11, 2012 at 7:21 AM, Peter Irbizon <peterirbizon@gmail.com> wrote:
Hello, I am using psycopg2 in windows app for example:
import psycopg2
import psycopg2.extras
self.con = psycopg2.connect("dbname= host= user= password= port=");
self.cur = self.con.cursor(cursor_factory=psycopg2.extras.DictCursor)
 
SELECT = "select something" 
self.cur.execute(SELECT)
 
for row in self.cur:
 ...
 
self.cur.close()
self.con.close()
 
But when I click on exit button in application MS Visual C++ runtime library error occurs: This application has requested the runtime to terminate it in unusual way.
What am I doing wrong?

Re: after application close MS Visual C++ runtime library error occurs

From
Peter Irbizon
Date:
Hello Jason, thanks for your effort again and sorry for my late answer.
To remove all "uniquenesses" of my program I removed all unnecessary pieces of code and left only this:
# -*- coding: utf-8 -*-

import pygtk
pygtk.require("2.0")
import gtk
import psycopg2
import psycopg2.extras 
conn = psycopg2.connect("dbname='' host='' user='' password='' port=''");

cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("select * from table")
print "\nShow me the databases:\n"
for row in cur:
   aa       = '%(bb)s' % row
   bb = '%(aa)s' % row
   print aa + ' '+ bb
cur.close()
conn.close()
 
but in my case it appears again. As I mentiones when I reorder importing - for example import psycopg2 goes to second line it works ok. I am not so experienced user of python to be able to say what causes this behaviour. sorry. maybe it can be really "networking" in pygtk library and maybe not. But it is quite interesting that in your case you can reproduce this behaviour. thanks again for your help .

2012/1/12 Jason Erickson <jason.erickson@stickpeople.com>
Thanks for the info and update, Peter.  Interesting that it ran alright after rearranging the the import order.

Initially I was thinking some common library that both modules use was not being cleaned up correctly on exit/tear down.  Could still be the case, but not seeing the commonality between the two.  Correct me if I'm wrong, as I'm not familiar with pygtk, but I did not see a 'networking' library in pygtk (for example, pyqt has the qtnetwork module).


I did try a simple pygtk script (the hello world example from pygtk) and added psycopg code to it, but unfortunatley was not able to duplicate the problem.  Can you think of any uniqueness to your program?  You mentioned a timer, are you spawning off a thread yourself, using the gtk timer, or something else?

-jason

 

Re: after application close MS Visual C++ runtime library error occurs

From
Peter Irbizon
Date:
well, I found out it must be some problem with gtk module.  When I leave
import gtk
import psycopg2
it this order it appears again.

2012/1/17 Peter Irbizon <peterirbizon@gmail.com>
Hello Jason, thanks for your effort again and sorry for my late answer.
To remove all "uniquenesses" of my program I removed all unnecessary pieces of code and left only this:
# -*- coding: utf-8 -*-

import pygtk
pygtk.require("2.0")
import gtk
import psycopg2
import psycopg2.extras 
conn = psycopg2.connect("dbname='' host='' user='' password='' port=''");

cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("select * from table")
print "\nShow me the databases:\n"
for row in cur:
   aa       = '%(bb)s' % row
   bb = '%(aa)s' % row
   print aa + ' '+ bb
cur.close()
conn.close()
 
but in my case it appears again. As I mentiones when I reorder importing - for example import psycopg2 goes to second line it works ok. I am not so experienced user of python to be able to say what causes this behaviour. sorry. maybe it can be really "networking" in pygtk library and maybe not. But it is quite interesting that in your case you can reproduce this behaviour. thanks again for your help .

2012/1/12 Jason Erickson <jason.erickson@stickpeople.com>
Thanks for the info and update, Peter.  Interesting that it ran alright after rearranging the the import order.

Initially I was thinking some common library that both modules use was not being cleaned up correctly on exit/tear down.  Could still be the case, but not seeing the commonality between the two.  Correct me if I'm wrong, as I'm not familiar with pygtk, but I did not see a 'networking' library in pygtk (for example, pyqt has the qtnetwork module).


I did try a simple pygtk script (the hello world example from pygtk) and added psycopg code to it, but unfortunatley was not able to duplicate the problem.  Can you think of any uniqueness to your program?  You mentioned a timer, are you spawning off a thread yourself, using the gtk timer, or something else?

-jason