detecting existing instance

Report Bugs Here

detecting existing instance

Postby bjorn » Thu Jun 07, 2012 6:51 am

Hi,

I run Editra 7.0.1 on ubuntu 12.04 installed from source.
Editra does not seem to detect previous running instances of Editra ( I want new file to be opened as tabs in the running instance). The "open files in new windows" is unchecked.

There is a file created in the tmp dir called "Editra-bjorn" after starting editra.

thanks,
Bjorn
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Thu Jun 07, 2012 1:35 pm

Hi,

Editra opens a TCP port connection on the local loopback to perform communication between instances so that if a second instance opens up it sends the file name to the other one to open instead when a second instance is detected.

So if this is not working on your system the original instance must be failing to open its socket connection at port 27150. Check that any firewalls are not blocking that port on the local loopback address (127.0.0.1).

The 'Editra-username' file created after starting editra is a file mutex created by the toolkit to detect when more than one instance is running in one session. The file should be automatically deleted when all Editra instances are closed.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby bjorn » Sun Jun 10, 2012 5:58 am

Hi,

Thank you for your reply.

The debug messages below speak of an lpc server, is this related to the checking for other instances? I have no firewall installed to my knowledge. The second instance below does not seem to say anything about finding the first instance.

Netstat says that port 27150 is being listen to (see screenshot). This line disappears when all editra instances are closed.

/bjorn

bjorn@bjorn-UL30A:~$ editra -d&
[2] 23114
[1] Done editra
bjorn@bjorn-UL30A:~$ [06:42:32][main][app] Initializing application...
[06:42:33][app][info] Editra is Initializing
[06:42:33][profile][info] Loaded /home/bjorn/.config/Editra/profiles/default.ppb
[06:42:33][app][info] Loaded Locale 'en_US'
[06:42:33][app][info] Starting Ipc server...
[06:42:33][pluginmgr][info] Found plugin: pyshell
[06:42:33][pluginmgr][info] Creating Instance of PyShell
[06:42:33][pluginmgr][info] Cached Plugin: PyShell
[06:42:33][pluginmgr][info] Found plugin: filebrowser
[06:42:33][pluginmgr][info] Creating Instance of FileBrowser
[06:42:33][pluginmgr][info] Cached Plugin: FileBrowser
[06:42:33][pluginmgr][info] Found plugin: codebrowser
[06:42:33][pluginmgr][info] Creating Instance of CodeBrowser
[06:42:33][pluginmgr][info] Cached Plugin: CodeBrowser
[06:42:33][pluginmgr][info] Found plugin: launch
[06:42:33][pluginmgr][info] Creating Instance of Launch
[06:42:33][pluginmgr][info] Cached Plugin: Launch
[06:42:33][app][info] Registering Editra's ArtProvider
[06:42:33][ed_style][info] Loaded custom style sheet /usr/local/lib/python2.7/dist-packages/Editra/styles/Default.ess
[06:42:33][ed_stc][evt] Code Folding Turned On
[06:42:33][ed_stc][evt] Bracket Highlighting Turned On
[06:42:33][docpositionmgr][info] successfully loaded book
[06:42:33][ed_pages][evt] New Page Created
[06:42:33][ed_pages][evt] Control Changing from Page: -1 to Page: 0
[06:42:33][ed_pages][evt] Page Changed to 0
[06:42:33][ed_editv][info] Tab has file:
[06:42:33][ed_stc][info] Lexer change notification for context -206
[06:42:33][keybinder][info] Loading Default Keybindings
[06:42:34][ed_main][info] Loading MainWindow Plugins
[06:42:34][ed_main][info] Loading Generator plugins
[06:42:34][main][info] Starting MainLoop...
[06:42:36][app][info] Going to sleep
bjorn@bjorn-UL30A:~$ editra -d&
[3] 23133
bjorn@bjorn-UL30A:~$ [06:43:15][main][app] Initializing application...
[06:43:16][app][info] Editra is Initializing
[06:43:16][profile][info] Loaded /home/bjorn/.config/Editra/profiles/default.ppb
[06:43:16][app][info] Loaded Locale 'en_US'
[06:43:16][app][info] Sending: <?xml version="1.0" ?><edipc />
[06:43:16][pluginmgr][info] Found plugin: pyshell
[06:43:16][pluginmgr][info] Creating Instance of PyShell
[06:43:16][pluginmgr][info] Cached Plugin: PyShell
[06:43:16][pluginmgr][info] Found plugin: filebrowser
[06:43:16][pluginmgr][info] Creating Instance of FileBrowser
[06:43:16][pluginmgr][info] Cached Plugin: FileBrowser
[06:43:16][pluginmgr][info] Found plugin: codebrowser
[06:43:16][pluginmgr][info] Creating Instance of CodeBrowser
[06:43:16][pluginmgr][info] Cached Plugin: CodeBrowser
[06:43:16][pluginmgr][info] Found plugin: launch
[06:43:16][pluginmgr][info] Creating Instance of Launch
[06:43:16][pluginmgr][info] Cached Plugin: Launch
[06:43:16][app][info] Registering Editra's ArtProvider
[06:43:16][ed_style][info] Loaded custom style sheet /usr/local/lib/python2.7/dist-packages/Editra/styles/Default.ess
[06:43:16][ed_stc][evt] Code Folding Turned On
[06:43:16][ed_stc][evt] Bracket Highlighting Turned On
[06:43:16][docpositionmgr][info] successfully loaded book
[06:43:16][ed_pages][evt] New Page Created
[06:43:16][ed_pages][evt] Control Changing from Page: -1 to Page: 0
[06:43:16][ed_pages][evt] Page Changed to 0
[06:43:16][ed_editv][info] Tab has file:
[06:43:16][ed_stc][info] Lexer change notification for context -206
[06:43:16][keybinder][info] Loading Default Keybindings
[06:43:17][ed_main][info] Loading MainWindow Plugins
[06:43:17][ed_main][info] Loading Generator plugins
[06:43:17][main][info] Starting MainLoop...
[06:43:19][app][info] Going to sleep
Attachments
Screenshot.png
Netstat showing port 27150
Screenshot.png (200.28 KiB) Viewed 7970 times
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Mon Jun 11, 2012 12:10 am

Hi,

If you can find where Editra is installed on your system try to open the 'ed_ipc.py' file in the src directory and find the SendCommands function.

Add a print statement to the except block to see what kind of error is being thrown when the second instance tries to send the command. It appears to find the second instance but is failing to send the command over to it so instead of failing it falls back to opening a second instance.

Code: Select all
    except Exception, msg:
        print msg # <- New line to print error to console window
        return False
    else:
        return True
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby bjorn » Mon Jun 11, 2012 6:20 am

Hi,
I changed the code as you instructed to

except Exception, msg:
print ">>>===>>>", msg
return False
else:
return True

the output is now:

bjorn@bjorn-UL30A:~$ editra&
[1] 9266
bjorn@bjorn-UL30A:~$ editra&
[2] 9283
bjorn@bjorn-UL30A:~$ >>>===>>> 'ascii' codec can't encode character u'\xf6' in position 2: ordinal not in range(128)
editra&
[3] 9299
bjorn@bjorn-UL30A:~$ >>>===>>> 'ascii' codec can't encode character u'\xf6' in position 2: ordinal not in range(128)
editra&
[4] 9315
bjorn@bjorn-UL30A:~$ >>>===>>> 'ascii' codec can't encode character u'\xf6' in position 2: ordinal not in range(128)


btw, editra platform info says
Platform Info: (linux2, python 2.7.3,wxGTK 2.8.12.1, unicode, gtk2, wx-assertions-off, SWIG-1.3.29)

is this a utf8 / Latin-1 problem somewhere?

/bjorn
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby bjorn » Mon Jun 11, 2012 8:32 am

Hi,
I looked at the actual message that is sent to the existing instance:

björn Johansson2z3DCPzdVr8=;<?xml version="1.0" ?><edipc />;*EDEND*

seems to be the "ö" in my user name that editra does not like.
I dont know where I can set the username though, I could not find any setting.

thanks,
bjorn
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Mon Jun 11, 2012 3:44 pm

Hi,

Thanks for debugging the problem I can clearly see the issue now. It is due to the message key (part with your user name) being passed in as Unicode. The default encoding to byte string fails because the default encoding cant handle your name.

I will apply a fix for this later today and post a patch here that you can apply locally in the meantime.

Thanks!
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby cody » Mon Jun 11, 2012 4:11 pm

The following change in Editra.py should fix this issue. If you can verify on your system that would be great.

See around line 144 in Editra.py and make the changes indicated below. Either that or you can try the latest SVN code.

Code: Select all
                # TODO: need to process other command line options as well i.e) -g
                self._log("[app][info] Sending: %s" % exml.Xml)
                key = profiler.Profile_Get('SESSION_KEY')                                # New
                if ebmlib.IsUnicode(key):                                                       # New
                    key = key.encode(sys.getfilesystemencoding(), 'replace')     # New
                rval = ed_ipc.SendCommands(exml, key)                                # Changed
                # If sending the command failed then let the editor startup
                # a new instance
                if not rval:
                    self._isfirst = True
            else:
                self._log("[app][info] Starting Ipc server...")
                # Set the session key and save it to the users profile so
                # that other instances can access the server
                key = base64.b64encode(os.urandom(8), 'zZ')                        # Changed
                uname = wx.GetUserName()                                                 # New
                if ebmlib.IsUnicode(uname):                                                 # New
                    uname = uname.encode(sys.getfilesystemencoding(), 'replace') # New
                key = uname + key                                                               # Changed
                profiler.Profile_Set('SESSION_KEY', key)
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby bjorn » Tue Jun 12, 2012 9:53 am

Hi,

I now get this:

bjorn@bjorn-UL30A:~$ editra&
[1] 8398
bjorn@bjorn-UL30A:~$ editra&
[2] 8417
bjorn@bjorn-UL30A:~$ >>>===>>> 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)
recieved
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/Editra/src/ed_ipc.py", line 179, in run
if recieved.startswith(self.__key) and recieved.endswith(MSGEND):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)

there is more problems in the ed_ipc.py file.

I hardcoded the uname to "bjorn Johansson"
I also added print key at some places
I got less error messages, but two instances are still opened:

editra&
[1] 8070
bjorn@bjorn-UL30A:/usr/local/lib/python2.7/dist-packages/Editra/src$ editra&
[2] 8089
bjorn@bjorn-UL30A:/usr/local/lib/python2.7/dist-packages/Editra/src$ bjorn JohanssonJIW3esMddrA=;<?xml version="1.0" ?><edipc />;*EDEND*
recieved bjorn JohanssonJIW3esMddrA=;<?xml version="1.0" ?><edipc />;*EDEND* <type 'unicode'>
self.__key bjorn JohanssonJIW3esMddrA= <type 'str'>


thanks for your help!
/bjorn
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Tue Jun 12, 2012 1:29 pm

Sorry didn't really get a chance to test yesterday when making these changes.

Think I got this time, was able to test and reproduce the issue before but not after the changes in the following change sets.

ed_ipc.py
http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/Editra/src/ed_ipc.py?r1=71715&r2=71718

Editra.py
http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/Editra/src/Editra.py?r1=71715&r2=71718
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby bjorn » Tue Jun 12, 2012 6:14 pm

Hi and thanks for all your effort!
Now it works in the sense that I do not get any error messages, but I still get two windows after opening the second file, whereas I expected the second file to open in a new tab like gedit does? I understand that it works as expected on your computer?
cheers,
bjorn

bjorn@bjorn-UL30A:~/Desktop$ editra -dd&
[1] 2789
bjorn@bjorn-UL30A:~/Desktop$ [19:09:52][main][app] Initializing application...
[19:09:52][app][info] Editra is Initializing
[19:09:52][InitConfig][info] Loading profile: u'/home/bjorn/.config/Editra/profiles/default.ppb'
[19:09:52][profile][info] Loaded /home/bjorn/.config/Editra/profiles/default.ppb
[19:09:52][app][info] Loaded Locale 'en_US'
[19:09:52][app][info] Starting Ipc server...
[19:09:52][pluginmgr][info] Found plugin: pyshell
[19:09:52][pluginmgr][info] Creating Instance of PyShell
[19:09:52][pluginmgr][info] Cached Plugin: PyShell
[19:09:52][pluginmgr][info] Found plugin: filebrowser
[19:09:52][pluginmgr][info] Creating Instance of FileBrowser
[19:09:52][pluginmgr][info] Cached Plugin: FileBrowser
[19:09:52][pluginmgr][info] Found plugin: codebrowser
[19:09:52][pluginmgr][info] Creating Instance of CodeBrowser
[19:09:52][pluginmgr][info] Cached Plugin: CodeBrowser
[19:09:52][pluginmgr][info] Found plugin: launch
[19:09:52][pluginmgr][info] Creating Instance of Launch
[19:09:52][pluginmgr][info] Cached Plugin: Launch
[19:09:52][app][info] Registering Editra's ArtProvider
[19:09:52][ed_style][info] Loaded custom style sheet /usr/local/lib/python2.7/dist-packages/Editra/styles/Default.ess
[19:09:52][ed_stc][evt] Code Folding Turned On
[19:09:52][ed_stc][evt] Bracket Highlighting Turned On
[19:09:53][docpositionmgr][info] successfully loaded book
[19:09:53][ed_pages][evt] New Page Created
[19:09:53][ed_pages][evt] Control Changing from Page: -1 to Page: 0
[19:09:53][ed_pages][evt] Page Changed to 0
[19:09:53][ed_editv][info] Tab has file:
[19:09:53][ed_stc][info] Lexer change notification for context -206
[19:09:53][keybinder][info] Loading Default Keybindings
[19:09:53][ed_main][info] Loading MainWindow Plugins
[19:09:53][ed_main][info] Loading Generator plugins
[19:09:53][main][info] Starting MainLoop...
[19:09:56][app][info] Going to sleep

bjorn@bjorn-UL30A:~/Desktop$ editra -dd&
[2] 2809
bjorn@bjorn-UL30A:~/Desktop$ [19:10:01][main][app] Initializing application...
[19:10:01][app][info] Editra is Initializing
[19:10:01][InitConfig][info] Loading profile: u'/home/bjorn/.config/Editra/profiles/default.ppb'
[19:10:01][profile][info] Loaded /home/bjorn/.config/Editra/profiles/default.ppb
[19:10:01][app][info] Loaded Locale 'en_US'
[19:10:01][app][info] Sending: <?xml version="1.0" ?><edipc />
[19:10:01][app][info] IN OnCommandReceived
[19:10:01][app][info] OnCommandReceived <?xml version="1.0" ?><edipc />
[19:10:01][main][info] Second instance exiting...
[19:10:01][ed_style][info] Using cached style data
[19:10:01][ed_style][info] Loaded custom style sheet /usr/local/lib/python2.7/dist-packages/Editra/styles/Default.ess
[19:10:01][ed_stc][evt] Code Folding Turned On
[19:10:01][ed_stc][evt] Bracket Highlighting Turned On
[19:10:01][ed_pages][evt] New Page Created
[19:10:02][ed_pages][evt] Control Changing from Page: -1 to Page: 0
[19:10:02][ed_pages][evt] Page Changed to 0
[19:10:02][ed_editv][info] Tab has file:
[19:10:02][ed_stc][info] Lexer change notification for context -227
[19:10:02][keybinder][info] Loading Default Keybindings
[19:10:02][ed_main][info] Loading MainWindow Plugins
[19:10:02][ed_main][info] Loading Generator plugins
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Tue Jun 12, 2012 8:31 pm

Hi,

When you run 'editra -dd& from the command line the second time you didn't pass a file name to open so in this case it opens a second window but the second window is in the same instance of the application from the first instance you launched and the second one should exit. Think that this was intentional when no file is passed to mimic opening a new instance of the application.

If you pass a filename it should open in a new tab in the first instance (unless you have in your settings set it to open in a new window).

Have you tried this?

Code: Select all
>> editra &
>> editra somefile.txt &


First instance should start, then second one should pass the file open request to the original instance then exit.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: detecting existing instance

Postby bjorn » Wed Jun 13, 2012 8:33 am

ok!
it works asyou described!
Thanks you very much, seems like the problem is solved.
cheers,
bjorn
bjorn
User
 
Posts: 9
Joined: Tue Jan 20, 2009 9:43 am

Re: detecting existing instance

Postby cody » Wed Jun 13, 2012 1:59 pm

Great, thanks again for all the followup information.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron