Skip to content

Instantly share code, notes, and snippets.

from PyQt4 import Qt
def Signal(name, *args):
def get_signal(self):
if not hasattr(self, '_signallers'):
self._signallers = {}
if (name, args) not in self._signallers:
signal = Qt.pyqtSignal(*args, name=name)
signaller_type = type('Signaller', (Qt.QObject,), {name: signal})
self._signallers[name, args] = signaller_type()
@vxgmichel
vxgmichel / devicetest_with_events.py
Created May 11, 2016 08:53
Test file for using events with devicetest
from time import sleep
from devicetest import TangoTestContext
from PyTango import utils, EventType, DevState
from PyTango.server import Device, DeviceMeta, command, run
class Dummy(Device):
__metaclass__ = DeviceMeta
def init_device(self):
self.set_change_event('State', True, True)
@vxgmichel
vxgmichel / test_pr305.py
Created August 1, 2016 16:17
Non-interruptible asyncio program after PR #305
import asyncio
async def background():
while running:
await asyncio.sleep(0)
[x**2 for x in range(10**5)]
async def main():
return await asyncio.sleep(20, result='hello')
@vxgmichel
vxgmichel / tango-db.service
Created September 5, 2016 13:03
tango-db systemd service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/tango-db.service",
# containing
# .include /lib/systemd/system/tango-db.service
# ...make your changes here...
# or create a file "/etc/systemd/system/tango-db.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file tango-db.service itself is parsed.
#
@vxgmichel
vxgmichel / asyncio_executor.py
Last active September 12, 2020 12:23
An executor to run asyncio coroutines from synchronous code
"""Provide an executor to run asyncio coroutines in a shadow thread."""
import asyncio
from threading import Thread
from concurrent.futures import Executor
class AsyncioExecutor(Executor):
def __init__(self):
@vxgmichel
vxgmichel / aioudp.py
Last active February 15, 2024 00:12
High-level UDP endpoints for asyncio
"""Provide high-level UDP endpoints for asyncio.
Example:
async def main():
# Create a local UDP enpoint
local = await open_local_endpoint('localhost', 8888)
# Create a remote UDP enpoint, pointing to the first one
@vxgmichel
vxgmichel / multitasking.py
Last active November 2, 2016 16:42
Multitasking example using coroutines
import itertools
import collections
def run(tasks):
# Prepare
results = {}
count = itertools.count()
queue = collections.deque()
for task in tasks:
@vxgmichel
vxgmichel / primes.py
Created November 22, 2016 08:48
Fast eratosthenes prime generator with a cached wheel
"""Fast eratosthenes prime generator with a cached wheel"""
import sys
import time
import operator
from itertools import cycle, chain, accumulate, islice, count
from functools import lru_cache, reduce, partial
from contextlib import contextmanager
CACHE_LEVEL = 5
@vxgmichel
vxgmichel / monitoring.py
Created January 10, 2017 15:32
Command line interface for monitoring asyncio tasks
"""Command line interface for monitoring asyncio tasks."""
import os
import signal
import asyncio
import argparse
import traceback
import linecache
from itertools import count
@vxgmichel
vxgmichel / udpproxy.py
Created February 2, 2017 10:05
UDP proxy server using asyncio
"""UDP proxy server."""
import asyncio
class ProxyDatagramProtocol(asyncio.DatagramProtocol):
def __init__(self, remote_address):
self.remote_address = remote_address
self.remotes = {}