How to use the multitasking.killall function in multitasking

To help you get started, we’ve selected a few multitasking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ranaroussi / qtpylib / qtpylib / blotters / ibgw.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from qtpylib.blotters import BaseBlotter
from ezibpy import ezIBpy
import time

import multitasking
import signal
signal.signal(signal.SIGINT, multitasking.killall)


class Blotter(BaseBlotter):

    """ ib tws / gw """

    def run(self, *args, **kwargs):

        clientId = int(kwargs["clientId"]) if "clientId" in kwargs else 999

        self.ibConn = ezIBpy()
        self.ibConn.ibCallback = self.ibCallback

        while not self.ibConn.connected:
            self.ibConn.connect(
                clientId=int(clientId),
github ranaroussi / multitasking / example.py View on Github external
#     https://www.gnu.org/licenses/lgpl-3.0.en.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import time
import random
import signal
import multitasking

# kill all tasks on ctrl-c
signal.signal(signal.SIGINT, multitasking.killall)

# to wait for task to finish, use:
# signal.signal(signal.SIGINT, multitasking.wait_for_tasks)


@multitasking.task
def hello(count):
    sleep = random.randint(1, 10) / 2
    print("Hello %s (sleeping for %ss)" % (count, sleep))
    time.sleep(sleep)
    print("Goodbye %s (after for %ss)" % (count, sleep))


if __name__ == "__main__":
    for i in range(0, 10):
        hello(i + 1)
github ranaroussi / qtpylib / qtpylib / blotters / base.py View on Github external
import logging as _logging
import json as _json
import zmq as _zmq

import numpy as _np
import pandas as _pd
from qtpylib import tools
from abc import ABCMeta, abstractmethod

import tempfile
import os

import time
import multitasking
import signal
signal.signal(signal.SIGINT, multitasking.killall)


# =============================================
# check min, python version
if _sys.version_info < (3, 4):
    raise SystemError("QTPyLib requires Python version >= 3.4")

# =============================================


class BaseBlotter():

    __metaclass__ = ABCMeta

    def __init__(self, blotter, datastore=None, instruments=None,
                 pubport=55555, subport=55556, **kwargs):

multitasking

Non-blocking Python methods using decorators

Apache-2.0
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis

Popular multitasking functions