-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix deadlock on linux and add flood scheduler
- Loading branch information
Showing
5 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from .schedule import Policy, Action, Schedule | ||
from .frame_buffer import FrameBuffer | ||
from .remote_channel import RemoteChannel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
from random import random | ||
from enum import Enum, auto | ||
from time import sleep | ||
|
||
|
||
|
||
class Policy(Enum): | ||
WAIT = auto() | ||
KILL = auto() | ||
|
||
|
||
class Action(Enum): | ||
CONTINUE = auto() | ||
WAIT = auto() | ||
KILL = auto() | ||
|
||
|
||
class Schedule(object): | ||
|
||
def __init__(self, threshold, t_wait=0, r_wait=1, policy=Policy.WAIT): | ||
self._threshold = threshold | ||
self._t_wait = t_wait | ||
self._r_wait = r_wait | ||
self._policy = policy | ||
self._reset() | ||
|
||
@property | ||
def count(self): | ||
return self._count | ||
|
||
@property | ||
def wait(self): | ||
return self._t_wait + self._r_wait*random() | ||
|
||
def _reset(self): | ||
self._count = 0 | ||
|
||
def __call__(self): | ||
self._count += 1 | ||
|
||
if self._count > self._threshold: | ||
self._reset() | ||
if self._policy == Policy.WAIT: | ||
# print("wating", flush=True) | ||
sleep(self.wait) | ||
return Action.WAIT | ||
if self._policy == Policy.KILL: | ||
return Action.KILL | ||
else: | ||
return Action.CONTINUE |