Skip to content

Commit

Permalink
Merge from 2.3: Fix for issue #2363 and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jun 8, 2015
2 parents 76a9a5f + 5a9179f commit 603e079
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
8 changes: 4 additions & 4 deletions spyderlib/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ def setup_page(self):
run_group = QGroupBox(_("Run"))
saveall_box = newcb(_("Save all files before running script"),
'save_all_before_run')

run_selection_group = QGroupBox(_("Run selection"))
focus_box = newcb(_("Maintain focus in the Editor after running cells or selections"),
'focus_to_editor')
focus_box = newcb(_("Maintain focus in the Editor after running cells "
"or selections"), 'focus_to_editor')

introspection_group = QGroupBox(_("Introspection"))
rope_is_installed = programs.is_module_installed('rope')
if rope_is_installed:
Expand Down
9 changes: 5 additions & 4 deletions spyderlib/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,11 +2483,12 @@ def open_external_console(self, fname, wdir, args, interact, debug, python,
python_args=to_text_string(python_args) )

def execute_in_external_console(self, lines, focus_to_editor):
"""Execute lines in external or IPython console
and eventually set focus to editor"""
"""
Execute lines in external or IPython console and eventually set focus
to the editor
"""
console = self.extconsole
if self.ipyconsole is None\
or self.last_console_plugin_focus_was_python:
if self.ipyconsole is None or self.last_console_plugin_focus_was_python:
console = self.extconsole
else:
console = self.ipyconsole
Expand Down
54 changes: 42 additions & 12 deletions spyderlib/start_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,54 @@ def main():
# instances started at the same time step in their
# own foots while trying to create the lock file
time.sleep(random.randrange(1000, 2000, 90)/10000.)

# Lock file creation
lockf = get_conf_path('spyder.lock')
lock = lockfile.FilesystemLock(lockf)

# lock.lock() tries to lock spyder.lock. If it fails,
# it returns False and so we try to start the client
if not lock.lock():
lock_file = get_conf_path('spyder.lock')
lock = lockfile.FilesystemLock(lock_file)

# Try to lock spyder.lock. If it's *possible* to do it, then
# there is no previous instance running and we can start a
# new one. If *not*, then there is an instance already
# running, which is locking that file
try:
lock_created = lock.lock()
except:
# If locking fails because of errors in the lockfile
# module, try to remove a possibly stale spyder.lock.
# This is reported to solve all problems with
# lockfile (See issue 2363)
try:
if os.name == 'nt':
if osp.isdir(lock_file):
import shutil
shutil.rmtree(lock_file, ignore_errors=True)
else:
if osp.islink(lock_file):
os.unlink(lock_file)
except:
pass

# Then start Spyder as usual and *don't* continue
# executing this script because it doesn't make
# sense
from spyderlib import spyder
spyder.main()
return

if lock_created:
# Start a new instance
if TEST is None:
atexit.register(lock.unlock)
from spyderlib import spyder
spyder.main()
else:
# Pass args to Spyder or print an informative
# message
if args:
send_args_to_spyder(args)
else:
print("Spyder is already running. If you want to open a new \n"
"instance, please pass to it the --new-instance option")
else:
if TEST is None:
atexit.register(lock.unlock)
from spyderlib import spyder
spyder.main()
else:
from spyderlib import spyder
spyder.main()
Expand Down
6 changes: 2 additions & 4 deletions spyderlib/utils/external/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from time import time as _uniquefloat

from spyderlib.py3compat import PY2, to_binary_string, to_text_string
from spyderlib.py3compat import PY2, to_binary_string

def unique():
if PY2:
Expand Down Expand Up @@ -63,7 +63,7 @@ def _is_pid_running(pid):
# that the process is still running.
return is_running or exit_code.value == STILL_ACTIVE

def kill(pid, signal):
def kill(pid, signal): # analysis:ignore
if not _is_pid_running(pid):
raise OSError(errno.ESRCH, None)
else:
Expand Down Expand Up @@ -130,7 +130,6 @@ class FilesystemLock:
def __init__(self, name):
self.name = name


def lock(self):
"""
Acquire this lock.
Expand Down Expand Up @@ -194,7 +193,6 @@ def lock(self):
self.clean = clean
return True


def unlock(self):
"""
Release this lock.
Expand Down

0 comments on commit 603e079

Please sign in to comment.