本文整理汇总了Python中Interrupt类的典型用法代码示例。如果您正苦于以下问题:Python Interrupt类的具体用法?Python Interrupt怎么用?Python Interrupt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interrupt类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
def runTest(self):
env = os.environ.copy()
env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
env["TMPDIR"] = self.tempdir
# build the node module with npm
node_dir = os.path.join(env["TMPDIR"], "fb-watchman")
shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, "node"), node_dir)
subprocess.check_call(["npm", "install"], cwd=node_dir)
env["TMP"] = env["TMPDIR"]
env["TEMP"] = env["TMPDIR"]
env["IN_PYTHON_HARNESS"] = "1"
env["NODE_PATH"] = "%s:%s" % (env["TMPDIR"], env.get("NODE_PATH", ""))
proc = subprocess.Popen(
self.getCommandArgs(),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail("Interrupted by SIGINT")
return
if status != 0:
self.fail(
"Exit status %d\n%s\n%s\n"
% (status, stdout.decode("utf-8"), stderr.decode("utf-8"))
)
return
self.assertTrue(True, self.getCommandArgs())
示例2: runTest
def runTest(self):
env = os.environ.copy()
env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
'tests.integration.', '').replace('.php', '')
env['TMPDIR'] = os.path.join(tempfile.tempdir, dotted)
os.mkdir(env['TMPDIR'])
env['TMP'] = env['TMPDIR']
env['TEMP'] = env['TMPDIR']
env['IN_PYTHON_HARNESS'] = '1'
proc = subprocess.Popen(
self.getCommandArgs(),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail('Interrupted by SIGINT')
return
if status != 0:
self.fail("Exit status %d\n%s\n%s\n" %
(status, stdout.decode('utf-8'), stderr.decode('utf-8')))
return
self.assertTrue(True, self.jsfile)
示例3: runTest
def runTest(self):
env = os.environ.copy()
env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
'tests.integration.', '').replace('.php', '')
env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted)
os.mkdir(env['TMPDIR'])
# build the node module with npm
node_dir = os.path.join(env['TMPDIR'], 'fb-watchman')
shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, 'node'), node_dir)
subprocess.check_call(['npm', 'install'], cwd=node_dir)
env['TMP'] = env['TMPDIR']
env['TEMP'] = env['TMPDIR']
env['IN_PYTHON_HARNESS'] = '1'
env['NODE_PATH'] = '%s:%s' % (env['TMPDIR'], env.get('NODE_PATH', ''))
proc = subprocess.Popen(
self.getCommandArgs(),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail('Interrupted by SIGINT')
return
if status != 0:
self.fail("Exit status %d\n%s\n%s\n" %
(status, stdout.decode('utf-8'), stderr.decode('utf-8')))
return
self.assertTrue(True, self.getCommandArgs())
示例4: _waitForCheck
def _waitForCheck(self, cond, res_check, timeout):
deadline = time.time() + timeout
res = None
while time.time() < deadline:
Interrupt.checkInterrupt()
res = cond()
if res_check(res):
return [True, res]
time.sleep(0.03)
return [False, res]
示例5: runner
def runner():
global results_queue
global tests_queue
try:
# Start up a shared watchman instance for the tests.
inst = WatchmanInstance.Instance()
inst.start()
# Allow tests to locate this default instance
WatchmanInstance.setSharedInstance(inst)
except Exception as e:
print('This is going to suck:', e)
return
while True:
test = tests_queue.get()
try:
if test == 'terminate':
break
if Interrupt.wasInterrupted():
continue
try:
result = Result()
test.run(result)
results_queue.put(result)
except Exception as e:
print(e)
finally:
tests_queue.task_done()
inst.stop()
示例6: test_cppclient
def test_cppclient(self):
env = os.environ.copy()
env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
proc = subprocess.Popen(
TEST_BINARY, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail("Interrupted by SIGINT")
return
if status != 0:
self.fail(
"Exit status %d\n%s\n%s\n"
% (status, stdout.decode("utf-8"), stderr.decode("utf-8"))
)
return
self.assertTrue(True, TEST_BINARY)
示例7: waitForSub
def waitForSub(self, name, root, accept=None, timeout=10, remove=True):
client = self.getClient()
def default_accept(dat):
return True
if accept is None:
accept = default_accept
deadline = time.time() + timeout
while time.time() < deadline:
Interrupt.checkInterrupt()
sub = self.getSubscription(name, root=root, remove=False)
if sub is not None:
res = accept(sub)
if res:
return self.getSubscription(name, root=root, remove=remove)
# wait for more data
client.setTimeout(deadline - time.time())
client.receive()
return None
示例8: interrupt_handler
def interrupt_handler(signo, frame):
Interrupt.setInterrupted()
示例9: shouldStop
def shouldStop(self):
if Interrupt.wasInterrupted():
return True
return super(Result, self).shouldStop()
示例10: runner
def runner():
global results_queue
global tests_queue
broken = False
try:
# Start up a shared watchman instance for the tests.
inst = WatchmanInstance.Instance(
{"watcher": args.watcher}, debug_watchman=args.debug_watchman
)
inst.start()
# Allow tests to locate this default instance
WatchmanInstance.setSharedInstance(inst)
if has_asyncio:
# Each thread will have its own event loop
asyncio.set_event_loop(asyncio.new_event_loop())
except Exception as e:
print("while starting watchman: %s" % str(e))
traceback.print_exc()
broken = True
while not broken:
test = tests_queue.get()
try:
if test == "terminate":
break
if Interrupt.wasInterrupted() or broken:
continue
result = None
for attempt in range(0, args.retry_flaky + 1):
# Check liveness of the server
try:
client = pywatchman.client(timeout=3.0, sockpath=inst.getSockPath())
client.query("version")
client.close()
except Exception as exc:
print(
"Failed to connect to watchman server: %s; starting a new one"
% exc
)
try:
inst.stop()
except Exception:
pass
try:
inst = WatchmanInstance.Instance(
{"watcher": args.watcher},
debug_watchman=args.debug_watchman,
)
inst.start()
# Allow tests to locate this default instance
WatchmanInstance.setSharedInstance(inst)
except Exception as e:
print("while starting watchman: %s" % str(e))
traceback.print_exc()
broken = True
continue
try:
result = Result()
result.setAttemptNumber(attempt)
if hasattr(test, "setAttemptNumber"):
test.setAttemptNumber(attempt)
test.run(result)
if hasattr(test, "setAttemptNumber") and not result.wasSuccessful():
# Facilitate retrying this possibly flaky test
continue
break
except Exception as e:
print(e)
if hasattr(test, "setAttemptNumber") and not result.wasSuccessful():
# Facilitate retrying this possibly flaky test
continue
if (
not result.wasSuccessful()
and "TRAVIS" in os.environ
and hasattr(test, "dumpLogs")
):
test.dumpLogs()
results_queue.put(result)
finally:
tests_queue.task_done()
if not broken:
inst.stop()
示例11: runTest
def runTest(self):
env = os.environ.copy()
env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
def clean_file_name(name):
name = name.replace(os.sep, '')
name = name.replace('tests.integration', '')
name = name.replace('.php', '')
name = name.replace('_php', '')
name = name.replace('.runTest', '')
return name
dotted = clean_file_name(os.path.normpath(self.id()))
env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted)
if os.name != 'nt' and len(env['TMPDIR']) > 94:
self.fail('temp dir name %s is too long for unix domain sockets' %
env['TMPDIR'])
os.mkdir(env['TMPDIR'])
env['TMP'] = env['TMPDIR']
env['TEMP'] = env['TMPDIR']
env['IN_PYTHON_HARNESS'] = '1'
env['WATCHMAN_PYTHON_BINARY'] = sys.executable
proc = subprocess.Popen(
self.getCommandArgs(),
cwd=env.get('WATCHMAN_SRC_DIR', os.getcwd()),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail('Interrupted by SIGINT')
return
if status != 0:
self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
return
res_pat = re.compile(b'^(not )?ok (\d+) (.*)$')
diag_pat = re.compile(b'^# (.*)$')
plan_pat = re.compile(b'^1\.\.(\d+)$')
# Now parse the TAP output
lines = stdout.replace(b'\r\n', b'\n').split(b'\n')
last_test = 0
diags = None
plan = None
for line in lines:
res = plan_pat.match(line)
if res:
plan = int(res.group(1))
continue
res = res_pat.match(line)
if res:
this_test = int(res.group(2))
if this_test != last_test + 1:
print(stdout, stderr)
self.fail('Expected test number %d, got %d' % (
last_test + 1,
this_test))
last_test = this_test
if res.group(1) == b'not ':
# Failed
msg = line
if diags is not None:
msg = msg + b'\n' + b'\n'.join(diags)
self.fail(msg.decode('utf-8'))
failed
diags = None
continue
res = diag_pat.match(line)
if res:
if diags is None:
diags = []
diags.append(res.group(1))
continue
if line != b'':
print('Invalid tap output from %s: %s' %
(self.id(), line))
if plan is None:
self.fail('no plan was observed')
else:
self.assertEqual(last_test, plan,
'%s planned %d but executed %s tests' % (
self.id(),
plan,
last_test))
示例12: runTest
def runTest(self):
env = os.environ.copy()
env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
proc = subprocess.Popen(
self.getCommandArgs(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail('Interrupted by SIGINT')
return
if status != 0:
self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
return
res_pat = re.compile('^(not )?ok (\d+) (.*)$')
diag_pat = re.compile('^# (.*)$')
# Now parse the TAP output
lines = stdout.split('\n')
# first line is the plan
try:
plan = int(lines.pop(0).split('..')[1])
except Exception as e:
self.fail(stdout + '\n' + stderr)
return
last_test = 0
diags = None
for line in lines:
res = res_pat.match(line)
if res:
this_test = int(res.group(2))
if this_test != last_test + 1:
print(stdout, stderr)
self.fail('Expected test number %d, got %d' % (
last_test + 1,
this_test))
last_test = this_test
if res.group(1) == 'not ':
# Failed
msg = line
if diags is not None:
msg = msg + '\n'.join(diags)
self.fail(msg)
failed
diags = None
continue
res = diag_pat.match(line)
if res:
if diags is None:
diags = []
diags.append(res.group(1))
continue
if line != '':
print('Invalid tap output from %s: %s' %
(self.id(), line))
self.assertEqual(last_test, plan,
'%s planned %d but executed %d tests' % (
self.id(),
plan,
last_test))
示例13: runTest
def runTest(self):
env = os.environ.copy()
env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
dotted = os.path.normpath(self.id()).replace(os.sep, ".").replace("tests.integration.", "").replace(".php", "")
env["TMPDIR"] = os.path.join(tempfile.tempdir, dotted)
if os.name != "nt" and len(env["TMPDIR"]) > 94:
self.fail("temp dir name %s is too long for unix domain sockets" % env["TMPDIR"])
os.mkdir(env["TMPDIR"])
env["IN_PYTHON_HARNESS"] = "1"
proc = subprocess.Popen(self.getCommandArgs(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
status = proc.poll()
if status == -signal.SIGINT:
Interrupt.setInterrupted()
self.fail("Interrupted by SIGINT")
return
if status != 0:
self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
return
res_pat = re.compile("^(not )?ok (\d+) (.*)$")
diag_pat = re.compile("^# (.*)$")
plan_pat = re.compile("^1\.\.(\d+)$")
# Now parse the TAP output
lines = stdout.split("\n")
last_test = 0
diags = None
plan = None
for line in lines:
res = plan_pat.match(line)
if res:
plan = int(res.group(1))
continue
res = res_pat.match(line)
if res:
this_test = int(res.group(2))
if this_test != last_test + 1:
print(stdout, stderr)
self.fail("Expected test number %d, got %d" % (last_test + 1, this_test))
last_test = this_test
if res.group(1) == "not ":
# Failed
msg = line
if diags is not None:
msg = msg + "\n".join(diags)
self.fail(msg)
failed
diags = None
continue
res = diag_pat.match(line)
if res:
if diags is None:
diags = []
diags.append(res.group(1))
continue
if line != "":
print("Invalid tap output from %s: %s" % (self.id(), line))
self.assertEqual(last_test, plan, "%s planned %d but executed %s tests" % (self.id(), plan, last_test))