我正在使用我分叉,修改和现在正在调试的python gui应用程序(对于自定义游戏控制器,如果您必须知道的话)。该应用程序启动一个子进程来处理与arduino的通信,该子进程启动各种功能来处理特定的操作。我试图在特定函数中内置TimeoutError异常,以便为我提供有关arduino无法响应的过程的更多信息,但是异常似乎没有得到适当的处理(请阅读:我没有知道该怎么做)。这是对函数的调用(仍在子进程中):
# STATE = Perform CNIA
if n_program_state == 4:
mQ.put((0, 'Starting CNIA...'))
try:
cnia(ser, conn, vessel) #This is the function that should raise the TimeoutError
except TimeoutError:
mq.put((1,'exception raised'))
mq.put((1, ' '.join(err.args)))
time.sleep(5)
pass
mQ.put((0, 'CNIA Complete'))
n_program_state = 5
这些是cnia函数的前几行,我在其中添加了一个伪造的timeouterror:
def cnia(ser, conn, vessel):
f_cnia_repeat = True
raise TimeoutError("clnr: fake timeout2")
...
当我运行程序并触发子进程时,消息队列会扩展到“正在启动CNIA”,然后子进程挂起。我希望它会引发异常,然后打印我指定的错误消息-我缺少什么?原作者声称没有专业知识,对模糊代码表示歉意,而且我可能会更糟。
答案 0 :(得分:-1)
我不太了解您的代码,但是我在这里可以解释的是,您甚至都没有接触过casper.options.verbose = true; // verbose reporting
casper.options.logLevel = 'debug'; // full log reporting
casper.options.exitOnError = false; // Keep going on error
const google_email = "EMAIL";
const google_passwd = "PASSWORD";
const loginUrl = 'https://accounts.google.com';
// Load the login page
casper.start(loginUrl, function() {
this.waitForSelector('#view_container'); // '> form' doesn't seem to work
});
// Fill in the 'username' form
casper.then(function() {
this.fill('form', {
identifier: google_email,
});
this.sendKeys('#view_container', casper.page.event.key.Enter , {keepFocus: true});
});
// First 'Enter' is too quick for Google, send another one after a pause
casper.wait(2500, function() {
this.sendKeys('#identifierId', casper.page.event.key.Enter , {keepFocus: true});
});
// Wait for the 'password' form
casper.waitForSelector("#passwordNext", function() {
this.echo("password form is apparently available");
});
// Password form seems to load slowly, even if the selector is found/visible, this delay ensures next form fill works
casper.wait(2500, function() {
this.echo("password form is really available");
});
// Fill in the 'password' form
casper.then(function() {
this.fill('form', {
password: google_passwd,
});
this.sendKeys('#view_container', casper.page.event.key.Enter , {keepFocus: true});
});
// First 'Enter' is too quick for Google, send another one after a pause
casper.wait(500, function() {
this.sendKeys('input.whsOnd.zHQkBf', casper.page.event.key.Enter , {keepFocus: true});
});
// Extend timeout to allow for slow dynamic page rendering
casper.options.waitTimeout = 25000;
casper.waitForSelector("#gb", function() {
this.echo("login complete");
});
casper.thenOpen('https://(google app you want)', function() {
// Check it opened okay
});
函数。尝试在cnia
之前添加print
,看看是否被调用
答案 1 :(得分:-1)
err.args可能正在创建未处理的异常。
尝试添加err对象:except TimeoutError as err: