Python 如何解决缺少多个ao.lock的问题?
我正在编写一个简单的pyS60应用程序,以前没有真正使用python或使用多线程,所以这对我来说有点新鲜。 为了保持应用程序打开,我在初始化应用程序主体后将e32.Ao_锁设置为wait(),然后在exit_key_处理程序上发出锁的信号 该程序可能执行的任务之一是打开第三方应用程序UpCode。这将扫描条形码并将条形码字符串复制到剪贴板。当我关闭UpCode时,我的应用程序应该恢复并从剪贴板粘贴输入。 我知道这可以通过使用Ao.lock实现,但我已经调用了一个实例。理想情况下,我的应用程序会在注意到某些内容已粘贴到剪贴板后重新获得焦点。 我能用睡眠或定时器功能完成我所需要的吗 您可以找到完整的脚本,我将其缩写为以下必要部分:Python 如何解决缺少多个ao.lock的问题?,python,multithreading,locking,nokia,pys60,Python,Multithreading,Locking,Nokia,Pys60,我正在编写一个简单的pyS60应用程序,以前没有真正使用python或使用多线程,所以这对我来说有点新鲜。 为了保持应用程序打开,我在初始化应用程序主体后将e32.Ao_锁设置为wait(),然后在exit_key_处理程序上发出锁的信号 该程序可能执行的任务之一是打开第三方应用程序UpCode。这将扫描条形码并将条形码字符串复制到剪贴板。当我关闭UpCode时,我的应用程序应该恢复并从剪贴板粘贴输入。 我知道这可以通过使用Ao.lock实现,但我已经调用了一个实例。理想情况下,我的应用程序会在
lock=e32.Ao_lock()
# Quit the script
def quit():
lock.signal()
# Callback function will be called when the requested service is complete.
def launch_app_callback(trans_id, event_id, input_params):
if trans_id != appmanager_id and event_id != scriptext.EventCompleted:
print "Error in servicing the request"
print "Error code is: " + str(input_params["ReturnValue"]["ErrorCode"])
if "ErrorMessage" in input_params["ReturnValue"]:
print "Error message is: " + input_params["ReturnValue"]["ErrorMessage"]
else:
print "\nWaiting for UpCode to close"
#lock.signal()
# launch UpCode to scan barcode and get barcode from clipboard
def scan_barcode():
msg('Launching UpCode to scan barcode.\nPlease exit UpCode after the barcode has been copied to the clipboard')
# Load appmanage service
appmanager_handle = scriptext.load('Service.AppManager', 'IAppManager')
# Make a request to query the required information in asynchronous mode
appmanager_id = appmanager_handle.call('LaunchApp', {'ApplicationID': u's60uid://0x2000c83e'}, callback=launch_app_callback)
#lock.wait()
#print "Request complete!"
barcode = clipboard.Get()
return barcode
# handle the selection made from the main body listbox
def handle_selection():
if (lb.current() == 0):
barcode = scan_barcode()
elif (lb.current() ==1):
barcode = clipboard.Get()
elif (lb.current() ==2):
barcode = input_barcode()
found = False
if is_barcode(barcode):
found, mbid, album, artist = identify_release(barcode)
else:
msg('Valid barcode not found. Please try again/ another method/ another CD')
return
if found:
go = appuifw.query(unicode('Found: ' + artist + ' - ' + album + '\nScrobble it?'), 'query')
if (go == 1):
now = datetime.datetime.utcnow()
scrobble_tracks(mbid, album, artist, now)
else:
appuifw.note(u'Scrobbling cancelled', 'info')
else:
appuifw.note(u'No match found for this barcode.', 'info')
# Set the application body up
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"ScanScrobbler"
entries = [(u"Scan a barcode", u"Opens UpCode for scanning"),
(u"Submit barcode from clipboard", u"If you've already copied a barcode there"),
(u"Enter barcode by hand", u"Using numeric keypad")
]
lb = appuifw.Listbox(entries, handle_selection)
appuifw.app.body = lb
lock.wait()
感谢所有帮助。我通过定义一个单独的第二个锁,并确保一次只有一个锁在等待,从而解决了这个问题。它似乎没有任何问题。可以找到当前代码