File tree Expand file tree Collapse file tree 2 files changed +42
-44
lines changed Expand file tree Collapse file tree 2 files changed +42
-44
lines changed Original file line number Diff line number Diff line change 33
33
34
34
_IS_SYNC = False
35
35
36
+ if _IS_SYNC :
37
+ PARENT = threading .Thread
38
+ else :
39
+ PARENT = object
36
40
37
- if not _IS_SYNC :
38
41
39
- class SimpleOp :
40
- def __init__ (self , client ):
41
- self .task = None
42
- self .client = client
43
- self .passed = False
42
+ class SimpleOp (PARENT ):
43
+ def __init__ (self , client ):
44
+ super ().__init__ ()
45
+ self .client = client
46
+ self .passed = False
47
+ self .task = None
44
48
45
- async def run (self ):
46
- await self .client .db .command ("ping" )
47
- self .passed = True # No exception raised.
49
+ async def run (self ):
50
+ await self .client .db .command ("ping" )
51
+ self .passed = True # No exception raised.
48
52
49
- def start (self ):
53
+ def start (self ):
54
+ if _IS_SYNC :
55
+ super ().start ()
56
+ else :
50
57
self .task = asyncio .create_task (self .run ())
51
58
52
- async def join (self ):
59
+ async def join (self ):
60
+ if _IS_SYNC :
61
+ super ().join ()
62
+ else :
53
63
await self .task
54
- else :
55
-
56
- class SimpleOp (threading .Thread ):
57
- def __init__ (self , client ):
58
- super ().__init__ ()
59
- self .client = client
60
- self .passed = False
61
-
62
- def run (self ):
63
- self .client .db .command ("ping" )
64
- self .passed = True # No exception raised.
65
64
66
65
67
66
async def do_simple_op (client , ntasks ):
Original file line number Diff line number Diff line change 33
33
34
34
_IS_SYNC = True
35
35
36
+ if _IS_SYNC :
37
+ PARENT = threading .Thread
38
+ else :
39
+ PARENT = object
36
40
37
- if not _IS_SYNC :
38
41
39
- class SimpleOp :
40
- def __init__ (self , client ):
41
- self .task = None
42
- self .client = client
43
- self .passed = False
42
+ class SimpleOp (PARENT ):
43
+ def __init__ (self , client ):
44
+ super ().__init__ ()
45
+ self .client = client
46
+ self .passed = False
47
+ self .task = None
44
48
45
- def run (self ):
46
- self .client .db .command ("ping" )
47
- self .passed = True # No exception raised.
49
+ def run (self ):
50
+ self .client .db .command ("ping" )
51
+ self .passed = True # No exception raised.
48
52
49
- def start (self ):
53
+ def start (self ):
54
+ if _IS_SYNC :
55
+ super ().start ()
56
+ else :
50
57
self .task = asyncio .create_task (self .run ())
51
58
52
- def join (self ):
59
+ def join (self ):
60
+ if _IS_SYNC :
61
+ super ().join ()
62
+ else :
53
63
self .task
54
- else :
55
-
56
- class SimpleOp (threading .Thread ):
57
- def __init__ (self , client ):
58
- super ().__init__ ()
59
- self .client = client
60
- self .passed = False
61
-
62
- def run (self ):
63
- self .client .db .command ("ping" )
64
- self .passed = True # No exception raised.
65
64
66
65
67
66
def do_simple_op (client , ntasks ):
You can’t perform that action at this time.
0 commit comments