### detaching file code.sage because it does not exist (deleted?) ###

84 views
Skip to first unread message

Sébastien Labbé

unread,
Sep 14, 2015, 4:52:24 AM9/14/15
to sage-devel
Dear sage-devel,

I love the attach command, but since more than a year, the attach command detaches my file almost each time I save it. I am using vim. Do emacs people get the same problem? Is it because when vim writes to the file, the file gets "deleted" temporarily? Does the attach command check the existence of the file 40 times each second?

The file is detached on the 4th save:

sage: %attach code.sage
sage:
### reloading attached file code.sage modified at 08:48:16 ###
### reloading attached file code.sage modified at 08:48:18 ###
### reloading attached file code.sage modified at 08:48:19 ###
sage: ### detaching file code.sage because it does not exist (deleted?) ###

The file is detached on the 2nd save:

sage: %attach code.sage
### reloading attached file code.sage modified at 08:48:31 ###
sage: ### detaching file code.sage because it does not exist (deleted?) ###

The file is detached on the 2nd save:

sage: %attach code.sage
### reloading attached file code.sage modified at 08:48:48 ###
sage: ### detaching file code.sage because it does not exist (deleted?) ###

The file is detached on the 2nd save:

sage: %attach code.sage
### reloading attached file code.sage modified at 08:48:53 ###
sage: ### detaching file code.sage because it does not exist (deleted?) ###

The file is detached on the 8th save:

sage: %attach code.sage
### reloading attached file code.sage modified at 08:49:01 ###
### reloading attached file code.sage modified at 08:49:03 ###
### reloading attached file code.sage modified at 08:49:04 ###
### reloading attached file code.sage modified at 08:49:05 ###
### reloading attached file code.sage modified at 08:49:06 ###
### reloading attached file code.sage modified at 08:49:08 ###
### reloading attached file code.sage modified at 08:49:09 ###
sage: ### detaching file code.sage because it does not exist (deleted?) ###


Sébastien

Volker Braun

unread,
Sep 14, 2015, 5:03:17 AM9/14/15
to sage-devel
Did you try :set backupcopy=yes in vim?

John Cremona

unread,
Sep 14, 2015, 5:15:38 AM9/14/15
to SAGE devel
It does not happen to me, using emacs.

John
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

Sébastien Labbé

unread,
Sep 14, 2015, 5:46:45 AM9/14/15
to sage-devel


On Monday, September 14, 2015 at 11:03:17 AM UTC+2, Volker Braun wrote:
Did you try :set backupcopy=yes in vim?

Thank you! You save my life!

Sébastien

Volker Braun

unread,
Sep 14, 2015, 6:51:48 AM9/14/15
to sage-devel
On Monday, September 14, 2015 at 11:46:45 AM UTC+2, Sébastien Labbé wrote:
Did you try :set backupcopy=yes in vim?
Thank you! You save my life!

Well, you'd still be better off using emacs ;-) 

Franco Saliola

unread,
Sep 15, 2015, 10:50:00 AM9/15/15
to sage-devel, Salvatore Stella
I also experience this problem sometimes, and especially when I'm using Dropbox like so: edit a file locally which is synced via Dropbox to a machine on which I run sage. This really triggers the problem.

Salvatore Stella (CCed) also had this problem and tried using this setting in vim. It seems to help, but it didn't solve the problem. It appears to depend on the latency of the network (i.e., this still happens if you are saving to a network drive).

To fix it, he patched his version of sage like so:

diff --git a/src/sage/repl/attach.py b/src/sage/repl/attach.py
index 9ebc3ef..00df8d4 100644
--- a/src/sage/repl/attach.py
+++ b/src/sage/repl/attach.py
@@ -514,9 +514,12 @@ def modified_file_iterator():
     for filename in attached.keys():
         old_tm = attached[filename]
         if not os.path.exists(filename):
-            print('### detaching file {0} because it does not exist (deleted?) ###'.format(filename))
-            detach(filename)
-            continue
+            # check again in a while to prevent race conditions on some editors
+            time.sleep(0.1)
+            if not os.path.exists(filename):
+                print('### detaching file {0} because it does not exist (deleted?) ###'.format(filename))
+                detach(filename)
+                continue
         new_tm = os.path.getmtime(filename)
         if new_tm > old_tm:
             modified[filename] = new_tm
Reply all
Reply to author
Forward
0 new messages