Unclosed connections

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Unclosed connections

Post by Starter »

Naonah wrote:I tried this and got syntax error, lol. Only this construction I wrote as last works :D
Did you replace the whole passage with my version? Because it works fine for me. oO
I have promises to keep and miles to go before I sleep.
User avatar
Naonah
Posts: 357
Joined: Sun Apr 04, 2010 11:12 pm

Re: Unclosed connections

Post by Naonah »

Starter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO
Anyway it is the same, you also closed 2 times the same connection :mrgreen:
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Unclosed connections

Post by Starter »

Naonah wrote:
Starter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO
Anyway it is the same, you also closed 2 times the same connection :mrgreen:
Huh? Maybe im a too bloody newbie at python but imo the openend connection is only 1 time closed (as needed) and only if an exception happens then another try to close the connection happens again. (at least this way its done at several more parts in the script when it comes to "prepareStatement")
I have promises to keep and miles to go before I sleep.
User avatar
Naonah
Posts: 357
Joined: Sun Apr 04, 2010 11:12 pm

Re: Unclosed connections

Post by Naonah »

ok, you are right :D
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
User avatar
Stake
Posts: 383
Joined: Sun Mar 23, 2008 9:33 pm
Location: Hungary
Contact:

Re: Unclosed connections

Post by Stake »

Why close a connection twice? It's enough for once.

Code: Select all

                 try :                     ins.executeUpdate()                 finally :                     ins.close()                     L2Databasefactory.close(con)
Last edited by Stake on Sun Oct 17, 2010 1:25 pm, edited 1 time in total.
Image
Image
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Unclosed connections

Post by Starter »

Stake wrote:Why close a connection twice? It's enough for once.

Code: Select all

                 try :                     ins.executeUpdate()                 finally :                     ins.close()                     L2Databasefactory.close(con)
The master solution?! Thx. :mrgreen:
I have promises to keep and miles to go before I sleep.
CrownXp
Posts: 8
Joined: Thu Sep 23, 2010 3:33 pm

Re: Unclosed connections

Post by CrownXp »

can upload the fixed file and close the thread, ill be soo fine xD
User avatar
Naonah
Posts: 357
Joined: Sun Apr 04, 2010 11:12 pm

Re: Unclosed connections

Post by Naonah »

Code: Select all

                 try :                     ins.executeUpdate()                 finally :                     ins.close()                     L2Databasefactory.close(con)
You cant use "finally" in Python.
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: Unclosed connections

Post by janiii »

yes, you can use finally in python:

http://docs.python.org/tutorial/errors. ... up-actions
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
User avatar
Stake
Posts: 383
Joined: Sun Mar 23, 2008 9:33 pm
Location: Hungary
Contact:

Re: Unclosed connections

Post by Stake »

Naonah wrote:

Code: Select all

                 try :                     ins.executeUpdate()                 finally :                     ins.close()                     L2Databasefactory.close(con)
You cant use "finally" in Python.
Never put close functions in try clause, always put them in finally, because you know, try only runs until exception is thrown, so if ins.close() throws an exception, L2Databasefactory.close() will not execute. But this way, all should work well.
Image
Image
User avatar
Naonah
Posts: 357
Joined: Sun Apr 04, 2010 11:12 pm

Re: Unclosed connections

Post by Naonah »

janiii wrote:yes, you can use finally in python:

http://docs.python.org/tutorial/errors. ... up-actions
oops, sry :oops: but I had syntax error when used "finally" :D
Stake wrote: Never put close functions in try clause, always put them in finally, because you know, try only runs until exception is thrown, so if ins.close() throws an exception, L2Databasefactory.close() will not execute. But this way, all should work well.
Thank you for your help. I just wrote this cuz after applying your codes I got syntax error (with "finally"). Anyway using your solution I fixed this :)
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
User avatar
Naonah
Posts: 357
Joined: Sun Apr 04, 2010 11:12 pm

Re: Unclosed connections

Post by Naonah »

Here, you have a proof that clause finally is not working in Python (maybe in other Python version). I have Python 2.2.1

Code: Select all

        if event == "delete" :            con=L2DatabaseFactory.getInstance().getConnection()            rem=con.prepareStatement("DELETE FROM buffer_scheme_list WHERE id=? LIMIT 1")            rem.setString(1, eventParam1)            try : rem.executeUpdate()            except : pass            rem=con.prepareStatement("DELETE FROM buffer_scheme_contents WHERE scheme_id=?")            rem.setString(1, eventParam1)            try :                rem.executeUpdate()                rem.close()            except : pass               finally : L2DatabaseFactory.close(con)            return rebuildMainHtml(st)
...and here result:

Code: Select all

Traceback (innermost last):  (no code object) at line 0SyntaxError: ('invalid syntax', ('__init__.py', 734, 25, '\t\t\tfinally : L2DatabaseFactory.close(con)'))
Thank you.
Best regards.
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: Unclosed connections

Post by janiii »

http://docs.python.org/reference/compou ... s.html#try
Changed in version 2.5: In previous versions of Python, try...except...finally did not work. try...except had to be nested in try...finally.

you dont need to write the except clause if you do only pass there. so you just have try and finally clause at the end, which works also for your python version.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
User avatar
Stake
Posts: 383
Joined: Sun Mar 23, 2008 9:33 pm
Location: Hungary
Contact:

Re: Unclosed connections

Post by Stake »

Or try the "nested" version. :)

Code: Select all

try :    try :        ins.executeUpdate()    except : pass # unnecessary, but needed if you want to handle an exceptionfinally :    ins.close()    L2Databasefactory.close(con)
Image
Image
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Unclosed connections

Post by jurchiks »

I think it's the other way around:

Code: Select all

try :    ins.executeUpdate()finally :    try :       L2Databasefactory.close(con)    except : pass
might be wrong though.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Post Reply