本文整理匯總了Python中win32event.WaitForSingleObject方法的典型用法代碼示例。如果您正苦於以下問題:Python win32event.WaitForSingleObject方法的具體用法?Python win32event.WaitForSingleObject怎麽用?Python win32event.WaitForSingleObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32event
的用法示例。
在下文中一共展示了win32event.WaitForSingleObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wait
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def wait(self, state, interval=0.1, channel=None):
"""Wait for the given state(s), KeyboardInterrupt or SystemExit.
Since this class uses native win32event objects, the interval
argument is ignored.
"""
if isinstance(state, (tuple, list)):
# Don't wait for an event that beat us to the punch ;)
if self.state not in state:
events = tuple([self._get_state_event(s) for s in state])
win32event.WaitForMultipleObjects(
events, 0, win32event.INFINITE)
else:
# Don't wait for an event that beat us to the punch ;)
if self.state != state:
event = self._get_state_event(state)
win32event.WaitForSingleObject(event, win32event.INFINITE)
示例2: wait
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def wait(self, state, interval=0.1, channel=None):
"""Wait for the given state(s), KeyboardInterrupt or SystemExit.
Since this class uses native win32event objects, the interval
argument is ignored.
"""
if isinstance(state, (tuple, list)):
# Don't wait for an event that beat us to the punch ;)
if self.state not in state:
events = tuple([self._get_state_event(s) for s in state])
win32event.WaitForMultipleObjects(events, 0, win32event.INFINITE)
else:
# Don't wait for an event that beat us to the punch ;)
if self.state != state:
event = self._get_state_event(state)
win32event.WaitForSingleObject(event, win32event.INFINITE)
示例3: __windows_start_process__
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def __windows_start_process__(self, binary_path, task_key, verbose):
import win32event
out_stream = sys.stdout if verbose else open(os.devnull, 'w')
loading_semaphore = win32event.CreateSemaphore(None, 0, 1,
'Global\\HOLODECK_LOADING_SEM' + self._uuid)
self._world_process = \
subprocess.Popen([binary_path, task_key, '-HolodeckOn', '-LOG=HolodeckLog.txt',
'-ForceRes', '-ResX=' + str(self._window_size[1]), '-ResY=' +
str(self._window_size[0]), '-TicksPerSec=' + str(self._ticks_per_sec),
'--HolodeckUUID=' + self._uuid],
stdout=out_stream, stderr=out_stream)
atexit.register(self.__on_exit__)
response = win32event.WaitForSingleObject(loading_semaphore, 100000) # 100 second timeout
if response == win32event.WAIT_TIMEOUT:
raise HolodeckException("Timed out waiting for binary to load")
示例4: run
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def run(self):
last_time = os.stat(self.filename)[stat.ST_MTIME]
while 1:
try:
rc = win32event.WaitForSingleObject(self.handle,
win32event.INFINITE)
win32file.FindNextChangeNotification(self.handle)
except win32event.error, details:
# handle closed - thread should terminate.
if details[0] != winerror.ERROR_INVALID_HANDLE:
raise
break
this_time = os.stat(self.filename)[stat.ST_MTIME]
if this_time != last_time:
print "Detected file change - flagging for reload."
self.change_detected = True
last_time = this_time
示例5: testNotifyChange
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def testNotifyChange(self):
def change():
hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, self.key_name)
try:
win32api.RegSetValue(hkey, None, win32con.REG_SZ, "foo")
finally:
win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, self.key_name)
evt = win32event.CreateEvent(None,0,0,None)
## REG_NOTIFY_CHANGE_LAST_SET - values
## REG_CHANGE_NOTIFY_NAME - keys
## REG_NOTIFY_CHANGE_SECURITY - security descriptor
## REG_NOTIFY_CHANGE_ATTRIBUTES
win32api.RegNotifyChangeKeyValue(win32con.HKEY_CURRENT_USER,1,win32api.REG_NOTIFY_CHANGE_LAST_SET,evt,True)
ret_code=win32event.WaitForSingleObject(evt,0)
# Should be no change.
self.failUnless(ret_code==win32con.WAIT_TIMEOUT)
change()
# Our event should now be in a signalled state.
ret_code=win32event.WaitForSingleObject(evt,0)
self.failUnless(ret_code==win32con.WAIT_OBJECT_0)
示例6: closeApp
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def closeApp(self, hProcess, title):
"""
Close Application by window title
"""
try:
win32gui.EnumWindows(FileWriterLauncherGui.enumCallback, title)
if proc is not None:
win32event.WaitForSingleObject(hProcess, 5 * 1000)
win32api.CloseHandle(hProcess)
for pid in self.genChildProcesses(proc):
try:
handle = win32api.OpenProcess(1, False, pid)
win32process.TerminateProcess(handle, -1)
win32api.CloseHandle(handle)
except:
pass
except:
pass
示例7: socket_bind_recv
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def socket_bind_recv(socket_fn, cmd_handler):
"""
非bsd係統的進程間通信,接受消息,處理消息,使用windows全局共享內存實現,
函數名稱保持與bsd的接口名稱一致
:param socket_fn: 共享內存文件名稱
:param cmd_handler: cmd處理函數,callable類型
"""
if not callable(cmd_handler):
print('socket_bind_recv cmd_handler must callable!')
while True:
global_fn = 'Global\\{}'.format(socket_fn)
event = w32e.CreateEvent(None, 0, 0, global_fn)
event_mmap = mmf.mmapfile(None, socket_fn, 1024)
w32e.WaitForSingleObject(event, -1)
socket_cmd = event_mmap.read(1024).decode()
# 把接收到的socket傳遞給外部對應的處理函數
cmd_handler(socket_cmd)
event_mmap.close()
win_api.CloseHandle(event)
示例8: Transmit
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def Transmit(self, transmitData):
"""
This will be called to detect available IR Blasters.
"""
if not self.file:
if not self.connecting:
self.Connect()
else:
return False
while self.receiving:
time.sleep(0.05)
writeOvlap = win32file.OVERLAPPED()
writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None)
win32file.WriteFile(self.file, transmitData, writeOvlap)
win32event.WaitForSingleObject(writeOvlap.hEvent, win32event.INFINITE)
return True
示例9: __windows_init__
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def __windows_init__(self):
import win32event
semaphore_all_access = 0x1F0003
self.timeout = 5000 if self.should_timeout else win32event.INFINITE
self._semaphore1 = \
win32event.OpenSemaphore(semaphore_all_access, False,
"Global\\HOLODECK_SEMAPHORE_SERVER" + self._uuid)
self._semaphore2 = \
win32event.OpenSemaphore(semaphore_all_access, False,
"Global\\HOLODECK_SEMAPHORE_CLIENT" + self._uuid)
def windows_acquire_semaphore(sem):
result = win32event.WaitForSingleObject(sem, self.timeout)
if result != win32event.WAIT_OBJECT_0:
raise TimeoutError("Timed out or error waiting for engine!")
def windows_release_semaphore(sem):
win32event.ReleaseSemaphore(sem, 1)
def windows_unlink():
pass
self._get_semaphore_fn = windows_acquire_semaphore
self._release_semaphore_fn = windows_release_semaphore
self.unlink = windows_unlink
示例10: poll
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def poll(self):
"""Check if child process has terminated. Returns returncode
attribute."""
if self.returncode == None:
if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self)
return self.returncode
示例11: wait
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def wait(self):
"""Wait for child process to terminate. Returns returncode
attribute."""
if self.returncode == None:
obj = WaitForSingleObject(self._handle, INFINITE)
self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self)
return self.returncode
示例12: wait_for_input
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def wait_for_input(self, timeout):
"""
Wait until there is some input or the timeout is hit.
:param timeout: Time to wait for input in seconds (floating point).
"""
rc = win32event.WaitForSingleObject(self._stdin, int(timeout * 1000))
if rc not in [0, 258]:
raise RuntimeError(rc)
示例13: transmit
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def transmit(self,dataToTransmit):
# convert to string
dataToTransmit = ''.join([chr(b) for b in dataToTransmit])
# write over tuntap interface
win32file.WriteFile(self.tuntap, dataToTransmit, self.overlappedTx)
win32event.WaitForSingleObject(self.overlappedTx.hEvent, win32event.INFINITE)
self.overlappedTx.Offset = self.overlappedTx.Offset + len(dataToTransmit)
#======================== private =========================================
示例14: testRecord
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def testRecord(self):
d = ds.DirectSoundCaptureCreate(None, None)
sdesc = ds.DSCBUFFERDESC()
sdesc.dwBufferBytes = 352800 # 2 seconds
sdesc.lpwfxFormat = pywintypes.WAVEFORMATEX()
sdesc.lpwfxFormat.wFormatTag = pywintypes.WAVE_FORMAT_PCM
sdesc.lpwfxFormat.nChannels = 2
sdesc.lpwfxFormat.nSamplesPerSec = 44100
sdesc.lpwfxFormat.nAvgBytesPerSec = 176400
sdesc.lpwfxFormat.nBlockAlign = 4
sdesc.lpwfxFormat.wBitsPerSample = 16
buffer = d.CreateCaptureBuffer(sdesc)
event = win32event.CreateEvent(None, 0, 0, None)
notify = buffer.QueryInterface(ds.IID_IDirectSoundNotify)
notify.SetNotificationPositions((ds.DSBPN_OFFSETSTOP, event))
buffer.Start(0)
win32event.WaitForSingleObject(event, -1)
event.Close()
data = buffer.Update(0, 352800)
fname=os.path.join(win32api.GetTempPath(), 'test_directsound_record.wav')
f = open(fname, 'wb')
f.write(wav_header_pack(sdesc.lpwfxFormat, 352800))
f.write(data)
f.close()
示例15: Connect
# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import WaitForSingleObject [as 別名]
def Connect(entryName, bUseCallback):
if bUseCallback:
theCallback = Callback
win32event.ResetEvent(callbackEvent)
else:
theCallback = None
# in order to *use* the username/password of a particular dun entry, one must
# explicitly get those params under win95....
try:
dp, b = win32ras.GetEntryDialParams( None, entryName )
except:
print "Couldn't find DUN entry: %s" % entryName
else:
hras, rc = win32ras.Dial(None, None, (entryName, "", "", dp[ 3 ], dp[ 4 ], ""),theCallback)
# hras, rc = win32ras.Dial(None, None, (entryName, ),theCallback)
# print hras, rc
if not bUseCallback and rc != 0:
print "Could not dial the RAS connection:", win32ras.GetErrorString(rc)
hras = HangUp( hras )
# don't wait here if there's no need to....
elif bUseCallback and win32event.WaitForSingleObject(callbackEvent, 60000)!=win32event.WAIT_OBJECT_0:
print "Gave up waiting for the process to complete!"
# sdk docs state one must explcitly hangup, even if there's an error....
try:
cs = win32ras.GetConnectStatus( hras )
except:
# on error, attempt a hang up anyway....
hras = HangUp( hras )
else:
if int( cs[ 0 ] ) == win32ras.RASCS_Disconnected:
hras = HangUp( hras )
return hras, rc