Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
A connection owned by a parent is unusable by a child if the parent
(the owning process) closes the connection.
"""
conn = Connection()
conn.send_command('ping')
assert conn.read_response() == b'PONG'
def target(conn, ev):
ev.wait()
# the parent closed the connection. because it also created the
# connection, the connection is shutdown and the child
# cannot use it.
with pytest.raises(ConnectionError):
conn.send_command('ping')
ev = multiprocessing.Event()
proc = multiprocessing.Process(target=target, args=(conn, ev))
proc.start()
conn.disconnect()
ev.set()
proc.join(3)
assert proc.exitcode == 0
# sys.path modification needed so nosetests can load the test_utils package.
sys.path.append(os.path.abspath(__REPO_ROOT))
# Because of the nature of the python-env loading of nosetests, we need to
# add the codechecker_gen package to the pythonpath here, so it is available
# for the actual test cases.
__PKG_ROOT = os.path.abspath(os.environ['CC_PACKAGE'])
__LAYOUT_FILE_PATH = os.path.join(__PKG_ROOT, 'config', 'package_layout.json')
with open(__LAYOUT_FILE_PATH) as layout_file:
__PACKAGE_LAYOUT = json.load(layout_file)
sys.path.append(os.path.join(
__PKG_ROOT, __PACKAGE_LAYOUT['static']['codechecker_gen']))
# Stopping event for CodeChecker server.
__STOP_SERVER = multiprocessing.Event()
def get_free_port():
'''Get a free port from the OS.'''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 0))
free_port = s.getsockname()[1]
s.close()
return free_port
def _wait_for_postgres_shutdown(workspace):
"""
Wait for PostgreSQL to shut down.
def setup(self):
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = LoadArrayTask(task_name='Test')
self.task.interface = CSVLoadInterface()
self.task.folder = FOLDER_PATH
self.task.filename = 'fake.dat'
self.root.children_task.append(self.task)
def start_component_and_wait_for_initialization(self, target):
signal_init = multiprocessing.Event()
signal_close = multiprocessing.Event()
process = multiprocessing.Process(target=target, args=(self.error_queue, signal_init, signal_close))
process.start()
# wait for initialization
signal_init.wait()
return (process, signal_close)
def _before_train(self):
assert gpu_available_in_session(), "[GPUUtilizationTracker] needs GPU!"
self._evt = mp.Event()
self._stop_evt = mp.Event()
self._queue = mp.Queue()
self._proc = mp.Process(target=self.worker, args=(
self._evt, self._queue, self._stop_evt))
ensure_proc_terminate(self._proc)
start_proc_mask_signal(self._proc)
def __init__(self, args, front_sink_addr):
super().__init__()
self.port = args.port_out
self.exit_flag = multiprocessing.Event()
self.logger = set_logger(colored('SINK', 'green'), args.verbose)
self.front_sink_addr = front_sink_addr
self.verbose = args.verbose
self.args = args
self._write_queue_after_pause = write_queue_after_pause
self._event_polling = Event()
self.event_bias_is_available = Event()
self.daemon = True
self._last_Fx = sharedctypes.RawValue(ct.c_float)
self._last_Fy = sharedctypes.RawValue(ct.c_float)
self._last_Fz = sharedctypes.RawValue(ct.c_float)
self._last_Tx = sharedctypes.RawValue(ct.c_float)
self._last_Ty = sharedctypes.RawValue(ct.c_float)
self._last_Tz = sharedctypes.RawValue(ct.c_float)
self._buffer_size = sharedctypes.RawValue(ct.c_uint64)
self._sample_cnt = sharedctypes.Value(ct.c_uint64)
self._event_stop_request = Event()
self._determine_bias_flag = Event()
self._bias_n_samples = 200
atexit.register(self.stop)
def _create_worker_process(self):
sentinel = Event()
w = self.Process(
force_execv=self._force_execv,
target=worker,
args=(self._inqueue, self._outqueue,
self._initializer, self._initargs,
self._maxtasksperchild,
sentinel),
)
self._pool.append(w)
w.name = w.name.replace('Process', 'PoolWorker')
w.daemon = True
w.start()
self._poolctrl[w.pid] = sentinel
return w
import argparse
import csv
import gzip
import mercantile
import multiprocessing
import os
import random
import requests
import signal
import tilepack.outputter
import time
import traceback
shutdown_event = multiprocessing.Event()
verbose = False
class ShutdownException(Exception):
pass
sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=200)
sess.mount('https://', adapter)
# def fetch_tile(x, y, z, type, layer, tile_size, tile_format, api_key):
def fetch_tile(format_args):
sleep_time = 0.5 * random.uniform(1.0, 1.7)
response_info = []
if shutdown_event.is_set():
raise ShutdownException("Shutdown event set")
lock = last_task.get_lock()
if lock.acquire(block):
try:
current_task = get_current_task_id()
if current_task != last_task.raw:
last_task.raw = current_task
results[current_task] = result = func(*args, **kwargs)
return result
return results.get(current_task, default)
finally:
executed.set()
lock.release()
last_task = multiprocessing.Array(ctypes.c_char, hashlib.md5().digest_size)
results = multiprocessing.Manager().dict()
executed = multiprocessing.Event()
_func.has_result = has_result
_func.reset = reset
_func.wait = wait
_func.set = set_result
_func.wrapped = func # compatibility with Fabric tasks
return _func