Merge remote-tracking branch 'imermcmaps/master', PR #1029
This commit is contained in:
@@ -66,6 +66,7 @@ def main():
|
|||||||
parser.add_option("-p", "--processes", dest="procs", action="store", type="int",
|
parser.add_option("-p", "--processes", dest="procs", action="store", type="int",
|
||||||
help="The number of local worker processes to spawn. Defaults to the number of CPU cores your computer has")
|
help="The number of local worker processes to spawn. Defaults to the number of CPU cores your computer has")
|
||||||
|
|
||||||
|
parser.add_option("--pid", dest="pid", action="store", help="Specify the pid file to use.")
|
||||||
# Options that only apply to the config-less render usage
|
# Options that only apply to the config-less render usage
|
||||||
parser.add_option("--rendermodes", dest="rendermodes", action="store",
|
parser.add_option("--rendermodes", dest="rendermodes", action="store",
|
||||||
help="If you're not using a config file, specify which rendermodes to render with this option. This is a comma-separated list.")
|
help="If you're not using a config file, specify which rendermodes to render with this option. This is a comma-separated list.")
|
||||||
@@ -138,6 +139,18 @@ def main():
|
|||||||
print("(build info not found)")
|
print("(build info not found)")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
if options.pid:
|
||||||
|
if os.path.exists(options.pid):
|
||||||
|
try:
|
||||||
|
with open(options.pid, 'r') as fpid:
|
||||||
|
pid = int(fpid.read())
|
||||||
|
if util.pid_exists(pid):
|
||||||
|
print("Already running (pid exists) - exiting..")
|
||||||
|
return 0
|
||||||
|
except IOError, ValueError:
|
||||||
|
pass
|
||||||
|
with open(options.pid,"w") as f:
|
||||||
|
f.write(str(os.getpid()))
|
||||||
# if --check-terrain was specified, but we have NO config file, then we cannot
|
# if --check-terrain was specified, but we have NO config file, then we cannot
|
||||||
# operate on a custom texture path. we do terrain checking with a custom texture
|
# operate on a custom texture path. we do terrain checking with a custom texture
|
||||||
# pack later on, after we've parsed the config file
|
# pack later on, after we've parsed the config file
|
||||||
@@ -493,6 +506,8 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
|
|||||||
logging.debug("Final cache stats:")
|
logging.debug("Final cache stats:")
|
||||||
for c in caches:
|
for c in caches:
|
||||||
logging.debug("\t%s: %s hits, %s misses", c.__class__.__name__, c.hits, c.misses)
|
logging.debug("\t%s: %s hits, %s misses", c.__class__.__name__, c.hits, c.misses)
|
||||||
|
if options.pid:
|
||||||
|
os.remove(options.pid)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import platform
|
|||||||
from string import hexdigits
|
from string import hexdigits
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from itertools import cycle, islice, product
|
from itertools import cycle, islice, product
|
||||||
|
import errno
|
||||||
def get_program_path():
|
def get_program_path():
|
||||||
if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
|
if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
|
||||||
return os.path.dirname(sys.executable)
|
return os.path.dirname(sys.executable)
|
||||||
@@ -391,3 +391,14 @@ try:
|
|||||||
OrderedDict = collections.OrderedDict
|
OrderedDict = collections.OrderedDict
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def pid_exists(pid): # http://stackoverflow.com/a/6940314/1318435
|
||||||
|
"""Check whether pid exists in the current process table."""
|
||||||
|
if pid < 0:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
os.kill(pid, 0)
|
||||||
|
except OSError, e:
|
||||||
|
return e.errno != errno.ESRCH
|
||||||
|
else:
|
||||||
|
return True
|
||||||
Reference in New Issue
Block a user