From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: emacsql-mysql - best way to close connection? Date: Sat, 1 Apr 2017 12:52:10 -0700 Message-ID: References: <8660ioy4zl.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1491076387 18292 195.159.176.226 (1 Apr 2017 19:53:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 1 Apr 2017 19:53:07 +0000 (UTC) Cc: Christopher Wellons To: Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 01 21:53:02 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuP4x-0003TW-2j for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Apr 2017 21:52:55 +0200 Original-Received: from localhost ([::1]:52667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuP52-0000IE-UX for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Apr 2017 15:53:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuP4c-0000I7-H7 for help-gnu-emacs@gnu.org; Sat, 01 Apr 2017 15:52:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuP4b-0001De-If for help-gnu-emacs@gnu.org; Sat, 01 Apr 2017 15:52:34 -0400 Original-Received: from mail-qk0-x229.google.com ([2607:f8b0:400d:c09::229]:34397) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuP4b-0001BV-Dg for help-gnu-emacs@gnu.org; Sat, 01 Apr 2017 15:52:33 -0400 Original-Received: by mail-qk0-x229.google.com with SMTP id d10so90271837qke.1 for ; Sat, 01 Apr 2017 12:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GrCwg2/Y8rmUpVa3Ab0FJI2svqU+7zBKFzNGafJsYC4=; b=AoRClOxVWCeQi9/SCpVEkZUX3GXswRkW68mSH3SsOKmr6iw9Bzizo8I8dv8Me5G3qg 0gadUmYNWVmN7bHltjAIgLm/T0wBEmYcoKO+QIF0QRvqY8rmSr+F78FemuYNIEKez2s3 NIBSOn032j5l9ceLyxQdDDDYY9WZ8OP+l/mBou/27RT54cdHl0nhiHm17zawYKHWGRH4 1NHP8geez5ssOxW7FWTP+VQy8HJZV1ZcGTF5YQgfKsFZHDoaUgrneRoBWGisI3Mp+K7x Q32aECw9S9cBYi/+uiEAySxWY+ZKGzAiiYg0oT42melqSHIWlX416hYJ3hDlDTJ8JW5P dp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GrCwg2/Y8rmUpVa3Ab0FJI2svqU+7zBKFzNGafJsYC4=; b=Zs4ir9ijbXZbYdm8az5uwUDbDk667aAc0AkDhqcNzCmyDerNmUDVYyDhqXpW7sHI/w eK0Uo49lus14Q6TaQxVEX28msVQaH0CjQfIU0+DvKI6NT19gZaXZtvlYGDJtdlHpDRUT oPERJAo+UWkCFu8qGp7IgV04Ha+jCkWaIjdhuo7Cn0/XNd8iympc2XTjS14lVAc5Tcg1 ucg8862ZMcowDvnFBt2llRfxmFKDWFBEf3h96ccJQg56O1RfmaCRkr4K/1dQJ/sEY5/5 FjaXquGjtyMMmiQNUEP+gADrA1F40fpHBHNO8TlgFDhGXg5eThR947V3ipAUDiRxm2t3 cMcA== X-Gm-Message-State: AFeK/H38aG2i5Xj6F5zNDXL0OW/TAaeeJeg5Upzt5UOw8Bsvx+SdtTZwYfEYlaqQY1kZleplcXBZaXjcgmoWIA== X-Received: by 10.55.128.70 with SMTP id b67mr8346516qkd.150.1491076350960; Sat, 01 Apr 2017 12:52:30 -0700 (PDT) Original-Received: by 10.237.49.162 with HTTP; Sat, 1 Apr 2017 12:52:10 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::229 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112673 Archived-At: Guido Van Hoecke wrote: >> I create a mysql connection in a let* form: >> >> (let* ((host "mysql.host.com") >> (dummy (netrc-credentials host)) ;; needed to define remaining netrc stuff >> (info (netrc-machine (netrc-parse (expand-file-name "~/.netrc")) host)) >> (id (cdr (assoc "login" info))) >> (pw (cdr (assoc "password" info))) >> (db (emacsql-mysql "database" :user id :password pw :host host))) >> ....) >> > I added (delete-process "emacsql-mysql") as last elisp form of the let* > form. This does kill the process. Still I wonder if this is the way to go? It looks like there's a function `emacsql-close' for that. If your code that uses the connection may raise an error (which would cause evaluation to never reach the call to `emacsql-close' or similar), then you may want to wrap it in `unwind-protect': (let* (... (db (emacsql-mysql "database" :user id :password pw :host host))) (unwind-protect (progn ...) (emacsql-close db))) Where you code that uses the connection would go inside the `progn'. There's also a macro `emacsql-with-connection' that encapsulates this pattern: create a connection, evaluate some forms, then ensure `emacsql-close' is called even in the event of an error. John