Skip to content

Commit 866a623

Browse files
authored
Merge pull request #145 from DCC-Lab/cleanup-import
Cleanup import, small module fixes
2 parents f6d54fa + b5d3b23 commit 866a623

File tree

13 files changed

+87
-20
lines changed

13 files changed

+87
-20
lines changed

dcclab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
from .utils import *
1414
from .DCCExceptions import *
1515

16-
__version__ = "1.1.1"
16+
__version__ = "1.1.2"
1717
__author__ = "Daniel Cote <dccote@cervo.ulaval.ca>"

dcclab/analysis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .computeengine import *
2+
from .labpca import *

dcclab/analysis/computeengine.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from threading import Thread
33
from queue import Empty
44
import time
5-
from json import dumps
65
import signal
7-
from database import *
6+
from dcclab.database import *
87

98
"""
109
A class to run many tasks in parallel when they are mostly independent. This engine is perfectly

dcclab/database/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def connect(self):
218218
pwd = keyring.get_password(serviceName, self.mysqlUser)
219219
if pwd is None:
220220
raise Exception(""" Set the password in the system password manager on the command line with:
221-
python -m keyring set {0} {1}""".format(serviceName, self.mysqlUser))
221+
{2} -m keyring set {0} {1}""".format(serviceName, self.mysqlUser, sys.executable))
222222
else:
223223
pwd = None
224224

@@ -524,7 +524,7 @@ def connect(self):
524524
pwd = keyring.get_password(serviceName, self.mysqlUser)
525525
if pwd is None:
526526
raise Exception(""" Set the password in the system password manager on the command line with:
527-
python -m keyring set {0} {1}""".format(serviceName, self.mysqlUser))
527+
{2} -m keyring set {0} {1}""".format(serviceName, self.mysqlUser, sys.executable))
528528
else:
529529
pwd = None
530530

dcclab/database/labdatadb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import numpy as np
33
import pandas as pd
44
import re
5-
from collections.abc import Iterable
65

76
class LabdataDB(MySQLDatabase):
87
"""

dcclab/image/cziUtil.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import xml.etree.ElementTree as ET
77
import os
88
import fnmatch
9-
import multiprocessing
109
import warnings
11-
from concurrent.futures import ThreadPoolExecutor
1210

1311
"""
1412
Python script containing utility functions to be used for handling .czi image.

dcclab/image/image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import PIL.Image
66
import matplotlib.pyplot as plt
77
import os
8-
import re
98
from typing import List, Union
109

1110

dcclab/ml/__init__.py

Whitespace-only changes.

dcclab/ml/dataset.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import List
33
import pandas as pd
44
import numpy as np
5-
import json
65
import os
76

87
"""

dcclab/tests/testComputeEngine.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import env
2+
import unittest
3+
from dcclab.analysis import *
4+
5+
def calculateFactorial(inputQueue, outputQueue):
6+
try:
7+
value = inputQueue.get_nowait()
8+
product = 1
9+
for i in range(value):
10+
product *= (i+1)
11+
outputQueue.put( (value, product) )
12+
except Empty as err:
13+
pass # not an error
14+
15+
def slowCalculation(inputQueue, outputQueue):
16+
try:
17+
value = inputQueue.get_nowait()
18+
time.sleep(3)
19+
outputQueue.put( value )
20+
except Empty as err:
21+
pass # not an error
22+
23+
def processSimple(queue):
24+
while not queue.empty():
25+
try:
26+
(n, nfactorial) = queue.get_nowait()
27+
print('Just finished calculating {0}!'.format(n))
28+
except Empty as err:
29+
break # we are done
30+
31+
32+
class MyTestCase(env.DCCLabTestCase):
33+
def testThreads1(self):
34+
N = 11
35+
print("Calculating n! for numbers 0 to {0} (every calculation is independent)".format(N - 1))
36+
print("======================================================================")
37+
38+
print("Using threads: fast startup time appropriate for quick calculations")
39+
engine = ComputeEngine(useThreads=True)
40+
for i in range(N):
41+
engine.inputQueue.put(i)
42+
engine.compute(target=calculateFactorial)
43+
44+
def testProcesses1(self):
45+
N = 11
46+
print("Using processes: long startup time appropriate for longer calculations")
47+
engine = ComputeEngine(useThreads=False)
48+
for i in range(N):
49+
engine.inputQueue.put(i)
50+
engine.compute(target=calculateFactorial)
51+
52+
def testThreadsProcessTask(self):
53+
N = 11
54+
print("Using threads and replacing the processTaskResult function")
55+
engine = ComputeEngine(useThreads=True)
56+
for i in range(N):
57+
engine.inputQueue.put(i)
58+
engine.compute(target=calculateFactorial, processTaskResults=processSimple)
59+
@unittest.skip
60+
def testProcessesVeryLong(self):
61+
N = 11
62+
print("Using processes with very long calculations and timeout")
63+
engine = ComputeEngine(useThreads=False)
64+
for i in range(N):
65+
engine.inputQueue.put(i)
66+
engine.compute(target=slowCalculation, timeoutInSeconds=2)
67+
68+
69+
if __name__ == '__main__':
70+
unittest.main()

0 commit comments

Comments
 (0)