Here are the examples of the python api sys.setswitchinterval taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
5
View Complete Implementation : test_sys.py
Copyright MIT License
Author : emilyemorehouse
Copyright MIT License
Author : emilyemorehouse
@unittest.skipUnless(threading, 'Threading required for this test.')
def test_switchinterval(self):
self.astertRaises(TypeError, sys.setswitchinterval)
self.astertRaises(TypeError, sys.setswitchinterval, 'a')
self.astertRaises(ValueError, sys.setswitchinterval, -1.0)
self.astertRaises(ValueError, sys.setswitchinterval, 0.0)
orig = sys.getswitchinterval()
self.astertTrue(orig < 0.5, orig)
try:
for n in (1e-05, 0.05, 3.0, orig):
sys.setswitchinterval(n)
self.astertAlmostEqual(sys.getswitchinterval(), n)
finally:
sys.setswitchinterval(orig)
3
View Complete Implementation : test_threadable.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def setUp(self):
"""
Reduce the CPython check interval so that thread switches happen much
more often, hopefully exercising more possible race conditions. Also,
delay actual test startup until the reactor has been started.
"""
if _PY3:
if getattr(sys, 'getswitchinterval', None) is not None:
self.addCleanup(sys.setswitchinterval, sys.getswitchinterval())
sys.setswitchinterval(0.0000001)
else:
if getattr(sys, 'getcheckinterval', None) is not None:
self.addCleanup(sys.setcheckinterval, sys.getcheckinterval())
sys.setcheckinterval(7)
0
View Complete Implementation : test_locks.py
Copyright MIT License
Author : emilyemorehouse
Copyright MIT License
Author : emilyemorehouse
def tearDown(self):
if self.old_switchinterval is not None:
sys.setswitchinterval(self.old_switchinterval)
0
View Complete Implementation : __init__.py
Copyright GNU General Public License v3.0
Author : lmintlcx
Copyright GNU General Public License v3.0
Author : lmintlcx
def on_start():
# don't need actually, will set to 0.5ms if game started
win32.timeBeginPeriod(1) # res == TIMERR_NOERROR
# this package is time-critical which needs real-time
gc.disable()
sys.setswitchinterval(0.001)
win32.SetPriorityClast(win32.GetCurrentProcess(), win32.HIGH_PRIORITY_CLast)
logger.enable_logger(False)
logger.set_logger_level("INFO")
mouse.get_dpi_scale()
if process.find_pvz_1051():
global pvz_priority_clast_original
pvz_priority_clast_original = win32.GetPriorityClast(process.pvz_handle)
if pvz_priority_clast_original != win32.REALTIME_PRIORITY_CLast:
win32.SetPriorityClast(process.pvz_handle, win32.HIGH_PRIORITY_CLast)
utils.update_game_base()
ui = utils.game_ui()
if ui in (2, 3):
scene.update_game_scene()
seeds.update_seeds_list() if ui == 3 else None
cobs.update_cob_cannon_list()
0
View Complete Implementation : win32priority.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pyglet
Copyright BSD 3-Clause "New" or "Revised" License
Author : pyglet
def priority_patch(
pin_thread = True,
pin_thread_mask = 0x01,
set_switch_interval = True,
switch_interval_value = 1./65.,
raise_priority=True,
priority_clast = 0x080,
patch_timer=True,
pin_process = False,
patch_event_loop=False,
):
import ctypes
try:
_winmm = ctypes.windll.winmm
except AttributeError:
raise NotImplementedError("This is not a Win32 compatible platform.")
if set_switch_interval:
import sys
sys.setswitchinterval(switch_interval_value)
time_start = _winmm.timeBeginPeriod
time_stop = _winmm.timeEndPeriod
_1 = ctypes.c_uint(1)
k32 = ctypes.windll.kernel32
if raise_priority:
k32.SetPriorityClast(-1, priority_clast)
import pyglet
if pin_thread:
k32.SetThreadAffinityMask(pyglet.app.platform_event_loop._event_thread,pin_thread_mask)
if pin_process:
k32.SetProcessAffinityMask(k32.GetCurrentProcess(), 1)
if patch_event_loop:
def idle(self):
self.clock.call_scheduled_functions(self.clock.update_time())
return self.clock.get_sleep_time(True)
pyglet.app.EventLoop.idle = idle
if patch_timer:
old_step = pyglet.clock.Clock.sleep
def new_step(*a, **ka):
time_start(_1)
old_step(*a,**ka)
time_stop(_1)
pyglet.clock.Clock.sleep=new_step