質問編集履歴
2
試したことを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -320,6 +320,212 @@
|
|
320
320
|
|
321
321
|
|
322
322
|
|
323
|
+
### 試したこと②
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
suchedule_event_run_print_hello内に記載されていたwhileをなくしました。
|
328
|
+
|
329
|
+
そうするとうまくいくようです。
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
```Python
|
334
|
+
|
335
|
+
import schedule
|
336
|
+
|
337
|
+
import time
|
338
|
+
|
339
|
+
import concurrent.futures
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
from datetime import datetime, timedelta
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
# ********************************
|
350
|
+
|
351
|
+
# 関数
|
352
|
+
|
353
|
+
# ********************************
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
def multi_thread():
|
360
|
+
|
361
|
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
|
362
|
+
|
363
|
+
executor.submit(suchedule_event_communicate)
|
364
|
+
|
365
|
+
executor.submit(suchedule_event_run_print_hello)
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
def get_timestring():
|
372
|
+
|
373
|
+
"""
|
374
|
+
|
375
|
+
ミリ秒までを保持できる現在時刻を取得
|
376
|
+
|
377
|
+
:return:
|
378
|
+
|
379
|
+
"""
|
380
|
+
|
381
|
+
now = datetime.now()
|
382
|
+
|
383
|
+
return now.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
def print_message(run_time=get_timestring(), message=""):
|
390
|
+
|
391
|
+
print(run_time + " : " + message)
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
def suchedule_event_communicate():
|
398
|
+
|
399
|
+
"""
|
400
|
+
|
401
|
+
3秒に一回時刻を表示する
|
402
|
+
|
403
|
+
:return:
|
404
|
+
|
405
|
+
"""
|
406
|
+
|
407
|
+
schedule.every(3/60).minutes.do(print_time)
|
408
|
+
|
409
|
+
while True:
|
410
|
+
|
411
|
+
schedule.run_pending()
|
412
|
+
|
413
|
+
time.sleep(1)
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
def print_time():
|
420
|
+
|
421
|
+
print_message(get_timestring(), "get_time")
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
def suchedule_event_run_print_hello():
|
428
|
+
|
429
|
+
"""
|
430
|
+
|
431
|
+
5秒に一回HELLO!!!を表示する
|
432
|
+
|
433
|
+
:return:
|
434
|
+
|
435
|
+
"""
|
436
|
+
|
437
|
+
schedule.every(5/60).minutes.do(print_hello)
|
438
|
+
|
439
|
+
# whileをなくしました。
|
440
|
+
|
441
|
+
schedule.run_pending()
|
442
|
+
|
443
|
+
time.sleep(1)
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
def print_hello():
|
450
|
+
|
451
|
+
now_time = get_timestring()
|
452
|
+
|
453
|
+
print_message(now_time, "HELLO!!!")
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
# HELLO!!!が表示されてから10秒間は待機時間
|
458
|
+
|
459
|
+
while str(datetime.strptime(now_time, '%Y-%m-%d %H:%M:%S.%f') + timedelta(
|
460
|
+
|
461
|
+
seconds=10)) > get_timestring():
|
462
|
+
|
463
|
+
print_message(get_timestring(), "待機状態です、、、")
|
464
|
+
|
465
|
+
time.sleep(3)
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
print_message(get_timestring(), "print_hello_exit")
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
# ********************************
|
476
|
+
|
477
|
+
# main
|
478
|
+
|
479
|
+
# ********************************
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
# 定期処理起動
|
486
|
+
|
487
|
+
multi_thread()
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
```
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
```
|
498
|
+
|
499
|
+
2019-04-05 10:00:37.653 : get_time
|
500
|
+
|
501
|
+
2019-04-05 10:00:39.653 : HELLO!!!
|
502
|
+
|
503
|
+
2019-04-05 10:00:39.661 : 待機状態です、、、
|
504
|
+
|
505
|
+
2019-04-05 10:00:42.661 : 待機状態です、、、
|
506
|
+
|
507
|
+
2019-04-05 10:00:45.661 : 待機状態です、、、
|
508
|
+
|
509
|
+
2019-04-05 10:00:48.662 : 待機状態です、、、
|
510
|
+
|
511
|
+
2019-04-05 10:00:51.662 : print_hello_exit
|
512
|
+
|
513
|
+
2019-04-05 10:00:52.662 : get_time
|
514
|
+
|
515
|
+
2019-04-05 10:00:55.662 : get_time
|
516
|
+
|
517
|
+
2019-04-05 10:00:56.662 : HELLO!!!
|
518
|
+
|
519
|
+
2019-04-05 10:00:56.663 : 待機状態です、、、
|
520
|
+
|
521
|
+
2019-04-05 10:00:59.663 : 待機状態です、、、
|
522
|
+
|
523
|
+
```
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
|
528
|
+
|
323
529
|
### 補足情報(FW/ツールのバージョンなど)
|
324
530
|
|
325
531
|
Python 3.7.0(pycharm使用)
|
1
コメントの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
"""
|
114
114
|
|
115
|
-
|
115
|
+
ミリ秒までを保持できる現在時刻を取得
|
116
116
|
|
117
117
|
:return:
|
118
118
|
|
@@ -260,7 +260,7 @@
|
|
260
260
|
|
261
261
|
"""
|
262
262
|
|
263
|
-
|
263
|
+
ミリ秒までを保持できる現在時刻を取得
|
264
264
|
|
265
265
|
:return:
|
266
266
|
|