How to use multitasking - 10 common examples

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 tbmoon / facenet / datasets / write_csv_for_making_dataset.py View on Github external
@multitasking.task
def generate_set(data, process_name, filename):
    print("The number of files: ", len(data))
    for idx, file in enumerate(data):
        if idx % 100 == 0:
            print("[{}/{}]".format(idx, len(data) - 1))
        '''    
        try:
            img = Image.open(file) # open the image file
            img.verify() # verify that it is, in fact, an image
        except (IOError, SyntaxError) as e:
            if verbosity == 1:
                print('Bad file:', file) # print out the names of corrupt files
            pass
        else:
            face_id    = os.path.basename(file).split('.')[0]
            face_label = os.path.basename(os.path.dirname(file))
github ranaroussi / multitasking / example.py View on Github external
@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))
github ranaroussi / qtpylib / qtpylib / blotters / base.py View on Github external
    @multitasking.task
    def _listen_to_socket(self, subport):
        socket = _zmq.Context().socket(_zmq.REP)
        socket.bind("tcp://*:%s" % str(subport))

        while True:
            msg = socket.recv_string()
            socket.send_string('[REPLY] %s' % msg)
            time.sleep(1)
github ranaroussi / pystore / pystore / collection.py View on Github external
    @multitasking.task
    def _list_items_threaded(self, **kwargs):
        self.items = self.list_items(**kwargs)
github tbmoon / facenet / mtcnn.py View on Github external
@multitasking.task
def start_cropping(paths, processname):
    for path in paths:
        if not valid_ext(path.suffix):
            print(get_dir_and_file(path), 'is not valid image. Expected extensions: .jpg, .jpeg, .png')
            continue
        detect_and_store(path, final_dir, args.resize, processname)
    print('Process', processname, 'finished!')
github ranaroussi / pystore / pystore / collection.py View on Github external
    @multitasking.task
    def write_threaded(self, item, data, metadata={},
                       npartitions=None, chunksize=None,
                       overwrite=False, epochdate=False,
                       reload_items=False, **kwargs):
        return self.write(item, data, metadata,
                          npartitions, chunksize, overwrite,
                          epochdate, reload_items,
                          **kwargs)
github ranaroussi / qtpylib / qtpylib / blotters / ibgw.py View on Github external
    @multitasking.task
    def ibCallback(self, caller, msg, **kwargs):

        # on event:
        # self.broadcast('kind', 'data')
        # self.datastore.save('kind', 'data')

        pass
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

55 / 100
Full package analysis

Popular multitasking functions