-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from aldanor/better-pytest-watch
Multiple directories support, norecursedirs, passing args to pytest
- Loading branch information
Showing
3 changed files
with
181 additions
and
48 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 | ||
|
||
from multiprocessing import Queue, Process, Event | ||
|
||
|
||
class Timer(Process): | ||
def __init__(self, interval, function, args=[], kwargs={}): | ||
super(Timer, self).__init__() | ||
self.interval = interval | ||
self.function = function | ||
self.args = args | ||
self.kwargs = kwargs | ||
self.finished = Event() | ||
|
||
def cancel(self): | ||
self.finished.set() | ||
|
||
def run(self): | ||
self.finished.wait(self.interval) | ||
if not self.finished.is_set(): | ||
self.function(*self.args, **self.kwargs) | ||
self.finished.set() | ||
|
||
|
||
class EventSpooler(object): | ||
def __init__(self, cooldown, callback): | ||
self.cooldown = cooldown | ||
self.callback = callback | ||
self.inbox = Queue() | ||
self.outbox = Queue() | ||
|
||
def enqueue(self, event): | ||
self.inbox.put(event) | ||
Timer(self.cooldown, self.process).start() | ||
|
||
def process(self): | ||
self.outbox.put(self.inbox.get()) | ||
if self.inbox.empty(): | ||
events = [] | ||
while not self.outbox.empty(): | ||
events.append(self.outbox.get()) | ||
self.callback(events) |
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