MCPcopy
hub / github.com/cherrypy/cherrypy / start

Method start

cherrypy/test/helper.py:442–498  ·  view source on GitHub ↗

Start cherryd in a subprocess.

(self, imports=None)

Source from the content-addressed store, hash-verified

440 f.write(str(conf))
441
442 def start(self, imports=None):
443 """Start cherryd in a subprocess."""
444 portend.free(self.host, self.port, timeout=1)
445
446 args = [
447 '-m',
448 'cherrypy',
449 '-c', self.config_file,
450 '-p', self.pid_file,
451 ]
452 r"""Command for running cherryd server with autoreload enabled.
453
454 Using
455
456 ```
457 ['-c',
458 "__requires__ = 'CherryPy'; \
459 import importlib.metadata, re, sys; \
460 sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]); \
461 sys.exit(\
462 importlib.metadata.distribution('cherrypy').entry_points[0])"]
463 ```
464
465 doesn't work as it's impossible to reconstruct the `-c`'s contents.
466 Ref: https://github.com/cherrypy/cherrypy/issues/1545
467 """
468
469 if not isinstance(imports, (list, tuple)):
470 imports = [imports]
471 for i in imports:
472 if i:
473 args.append('-i')
474 args.append(i)
475
476 if self.daemonize:
477 args.append('-d')
478
479 env = os.environ.copy()
480 # Make sure we import the cherrypy package in which this module is
481 # defined.
482 grandparentdir = os.path.abspath(os.path.join(thisdir, '..', '..'))
483 if env.get('PYTHONPATH', ''):
484 env['PYTHONPATH'] = os.pathsep.join(
485 (grandparentdir, env['PYTHONPATH']))
486 else:
487 env['PYTHONPATH'] = grandparentdir
488 self._proc = subprocess.Popen([sys.executable] + args, env=env)
489 if self.wait:
490 self.exit_code = self._proc.wait()
491 else:
492 portend.occupied(self.host, self.port, timeout=5)
493
494 # Give the engine a wee bit more time to finish STARTING
495 if self.daemonize:
496 time.sleep(2)
497 else:
498 time.sleep(1)
499

Callers 15

test_4_AutoreloadMethod · 0.95
test_5_Start_ErrorMethod · 0.95
test_daemonizeMethod · 0.95
test_SIGHUP_ttyMethod · 0.95
test_SIGTERMMethod · 0.95
cp_native_serverFunction · 0.45
startup_modpythonFunction · 0.45
run_modpythonFunction · 0.45
test_startFunction · 0.45

Calls 3

joinMethod · 0.80
getMethod · 0.45
waitMethod · 0.45

Tested by 15

test_4_AutoreloadMethod · 0.76
test_5_Start_ErrorMethod · 0.76
test_daemonizeMethod · 0.76
test_SIGHUP_ttyMethod · 0.76
test_SIGTERMMethod · 0.76
cp_native_serverFunction · 0.36
test_startFunction · 0.36
test_waitFunction · 0.36
set_startFunction · 0.36