This file contains hidden or 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
""" | |
A gevent friendly version of inotify | |
Either instanciate Inotify (or InotifyTree) objects directly from `ginotify.Inotify`: | |
```python | |
from ginotify import Inotify | |
ify1 = Inotify() |
This file contains hidden or 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
import time | |
import random | |
import threading | |
def sleep(): | |
time.sleep(random.random()) | |
N = 5 | |
sticks = [threading.Lock() for n in range(N)] |
This file contains hidden or 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
""" | |
Safe XML RPC calls in multiple gevent tasks. Basically, it serializes calls. | |
Assuming you are running a server like this:: | |
import time | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
def is_even(n): | |
time.sleep(3) |
This file contains hidden or 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
# I dare you to find an execution that prints out 0 | |
# (at least using the CPython implementation) | |
from threading import Thread | |
C, N = 0, 1_000_000 | |
def f(inc=1): | |
global C, N | |
for i in range(N): | |
C += inc |
This file contains hidden or 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
""" | |
tsb.py -- A telnet <-> serial port bridge | |
Copyright (C) 2005 Eli Fulkerson | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, |
This file contains hidden or 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
import hexdump | |
def binaries_gen(binaries): | |
""" | |
Generates a sequence of bytes from a seq<(offset, bytes)> | |
If there are gaps between the bytes the generator yields N None where N is | |
the length of the gap | |
Example:: |
This file contains hidden or 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
#!/usr/bin/env python3 | |
import time | |
import random | |
import logging | |
import gevent.server | |
DEFAULT_BIND = '' | |
DEFAULT_PORT = 45000 |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import time | |
import collections | |
class Motor(object): | |
Motion = collections.namedtuple('Motion', 'ipos fpos start_time end_time') |
This file contains hidden or 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
''' | |
An implementation object proxy pattern in python | |
Example:: | |
from proxy import Proxy | |
class A(object): | |
def __init__(self, base): | |
self.base = base | |
def plus(self, *a): |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# | |
# This file is part of the CT2 project | |
# | |
# Copyright 2015 European Synchrotron Radiation Facility, Grenoble, France | |
# | |
# Distributed under the terms of the LGPL license. | |
# See LICENSE.txt for more info. | |
""" CT2 (P201/C208) ESRF counter card |